Is it possible to add a watermark to a PDF using a transparent PNG with a certain opacity?

1 Answer 583 Views
PdfProcessing
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
Roland asked on 13 Feb 2022, 11:09 AM | edited on 13 Feb 2022, 11:11 AM

I've been scouring the docs, but I can't find anything.

I have to fall back to using a Syncfusion PDF, but I want to remove that dependency.

1 Answer, 1 is accepted

Sort by
0
Svilen
Telerik team
answered on 17 Feb 2022, 06:46 AM

Hello, Roland,

Svilen here, I will be glad to help out with this question. There is no out-of-the-box solution for adding a watermark for the PdfProcessing library. Our Developer Focused Example only includes a method for adding a text watermark. Still, I can suggest the following workaround. You can add the PNG image to the document and add the actual content afterward. I've attached a sample project, with some useful comments, where I create a new document and perform these actions. I've used the concepts from the following articles, which might be useful: 

  1. ImageSource
  2. Blocks


I hope this is helpful to you. Please let me know if I may further assist with this query.

Have a great day!

Regards,
Svilen
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Roland
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 21 Feb 2022, 12:42 PM | edited

I forgot to mention I am using Blazor with .NET 6. Your project targets .NET 4.

The Telerik.Documents.Fixed (not Windows)  does not seem to support .PNG images.

Svilen
Telerik team
commented on 22 Feb 2022, 01:14 PM

Hey, Roland,

Thank you for pointing this out. 

Since PDF only supports a number of compression filters like Jpeg and Jpeg2000, to export images different than Jpeg and Jpeg2000 or ImageQuality different than High, for .NET Standard/.NET 5+ one needs to provide an implementation of the JpegImageConverterBase abstract class. For your ease, I've already done this in the updated project version I have attached here. The project targets .NET 5 but the code will also work in .NET 6. Here is the fix for other image formats:

Telerik.Windows.Documents.Extensibility.JpegImageConverterBase jpegImageConverter = new Telerik.Documents.ImageUtils.JpegImageConverter();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.JpegImageConverter = jpegImageConverter;

This also requires the use of the Telerik.Documents.ImageUtils library. You can find more information on this topic in our Cross-Platform article. I've also added an additional example to the project, showing how to add the image to an existing file.

I hope this information helps. I'd be happy to further help if required.

Roland
Top achievements
Rank 3
Iron
Iron
Veteran
commented on 22 Feb 2022, 04:30 PM

PNGs no longer cause an exception, but it looks like a PNG is now converted to a JPG, which means no transparency.
A transparent logo now causes a white block superimposed on the background.
And if you draw the background after the logo you wipe out the logo.

Correct?

Svilen
Telerik team
commented on 23 Feb 2022, 12:26 PM

Hey, Roland,

Correct. We already have a public feedback item for creating a solution to this issue, which you can upvote here. We use such feedback to track interest in new features and respectively help our clients track their development. Currently, there is no workaround to the issue, for which I offer our sincere apologies! We hope to be able to soon implement this. Please follow the thread in order to track its development.

In the meantime, I remain at your disposal if any further help is required.

Tags
PdfProcessing
Asked by
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Svilen
Telerik team
Share this question
or