Set background color of text as transparent inside PDF - White box appear in the output

Hello,

I saw this example:

My understanding is that we can add background color transparency to the text state by using alpha color channel. So, it only changes the text fragment background color. If the PDF background is gray, to set text transparency, I have to select the gray alpha color channel and apply it to the text state of the text fragment written on the PDF. There is no real background color text transparency. Am I correct?

I tried to use the Aspose.Pdf.Color.Transparent, as indicated in the snippet below, to write in a PDF a text fragment with transparent BackgoundColor. At the position where the text fragment is appended, the PDF BackgroundColor is gray. But the text fragment written has rather a BackgroundColor white on the gray PDF BackgroundColor. What is the purpose of the Aspose.Pdf.Color.Transparent color?

using (var memoryStream = new MemoryStream(Properties.Resources.ResPdfFile))
{
	using (var pdfDocument = new Document(memoryStream))
	{				
		var page = (Page)pdfDocument.Pages[1];
		
		var textFragment = new TextFragment("My transparent background color text.");
		textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.Transparent;
		textFragment.Position = new Position(100, 475); // Write the text fragment where the PDF BackgroundColor is gray.
		
		var textBuilder = new TextBuilder(page);
		textBuilder.AppendText(textFragment);

		pdfDocument.Save( $"{nameof(Properties.Resources.ResPdfFile)}Output.pdf");
	}
}

Thanks.

Best regards,

N.

@nfortin

Thanks for contacting support.

We need to investigate the scenario in our environment and for the purpose, we need sample PDF document which you are using at your side. Would you kindly provide it so that we can test the scenario in our environment and address it accordingly.

Hello Asad Ali,

Thank you for helping.

I sent the PDF.

I use Aspose.PDF version 20.4 and had the same issue with version 18.2.

Best regards,

@nfortin

Would you please confirm that how and where you sent the PDF document as we did not receive any. Would you please use upload button in post editor to upload the attachment and make sure that it is uploaded.

Hello Asad Ali,

I sent it by using Aspose support email address.

It’s an email attachment. I send you once again as an attachment.

I don’t really want to upload that PDF unless I have no choice. Does the file is shared online? My understanding is that it is.

Best regards,

@nfortin

Regretfully we did not receive any email. However, you can send file in a private message as well. Please click over username and press Blue Message button to send the file.

Hello Asad Ali,

I sent you the file.

I finally found what is wrong. If I remove this line, it works:

textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.Transparent;

So no need to set the BackgroundColor property, if we want transparent background. If we set it, even to Transparent color, the background is white.

Best regards,

@nfortin

It is good to know that you managed to resolve your issue. However, we have logged an investigation ticket as PDFNET-48099 in our issue tracking system. We will further investigate the ticket in detail and share more insights with you on this behavior of the API as soon as it is resolved. Please spare us some time.

Hello Asad Ali,

Thank you for the feedback. I will spare you some time. I think it’s indeed an issue with the API. But at least the by default behavior when we don’t assign the property is correct.

Best regards,

@nfortin

Sure, we will surely investigate the issue on API end and share updates with you as soon as we have some.