-1

I'm using PDFsharp to use one PDF as a watermark in another PDF. This is mostly working. The watermark PDF is placed "behind" the content of each page in the target PDF. However, the watermark content needs to be partially transparent (or screened) in order for the resulting PDF to be legible.

How do I go about using PDFsharp to globally adjust the transparency of a PDF?

Ouroborus
  • 16,237
  • 4
  • 39
  • 62
  • According to this question it can't be done: http://stackoverflow.com/questions/16451008/image-opacity-in-pdfsharp-net – Bassie Jun 16 '16 at 16:15
  • @Bassie No, the answer clearly says "I don't know how". That's not the same as "can't be done". Given that PDFs can be seen as a series of drawing actions, at minimum it seems like it would be possible to change the transparency on the colors associated with those actions. I've dug into the API and am having difficulty even finding where to start. – Ouroborus Jun 16 '16 at 16:21

1 Answers1

1

You can check the documentation here for details on adding a watermark onto a pdf using PdfSharp. From the link:

Note: Technically the watermarks in this sample are simple graphical output. They have nothing to do with the Watermark Annotations introduced in PDF 1.5.

Here is another link which claims to have 3 different methods of applying watermarks - have you tried any of these? It looks like you may need to use MigraDocs as well as PdfSharp to achieve this.

You didn't specify what your watermark looks like - does it need to support any custom pdf you can create, or is it just some text going across the page? The latter definitely looks possible using the links I posted.

If you want to create custom objects, maybe you can check this link (Xforms), where it talks about drawing transparent custom shapes:

This sample shows how to create an XForm object from scratch. You can think of such an object as a template, that, once created, can be drawn frequently anywhere in your PDF document.

I think that perhaps instead of having 2 PDFs (1 main and 1 watermark) it is probably going to be easier to have 1 pdf and then create the watermark either with the built-in methods or by creating an XForm object and sticking it on the pdf.

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • This mostly matches my own research. I'd missed the bit covering Xforms but it appears that the transparencies they use are created on the fly rather than being applied to pre-existing elements or documents. I suspect that you're right in that PDFsharp/MigraDoc may not have the capability I'm looking for. – Ouroborus Jun 16 '16 at 22:53
  • 1
    @Ouroborus just found this question which seems like it might be helpful: http://stackoverflow.com/q/4226745/4671754 – Bassie Jun 16 '16 at 23:05
  • Unfortunately, iTextPdf's `PdfStamper` also doesn't have the ability to manipulate the transparency of its content. – Ouroborus Jun 16 '16 at 23:12