How can I add a watermark to my PDFs that are uploaded via the media library of the logged in WordPress User when viewing and printing the pdf.

I have tried utilizing plugins but they are all limited in one way or another.

The closest I was able to get was with the Premium WordPress plugin Secure PDF Embedder by WP-PDF and editing the containers styling to display the entire pdf as opposed to a single page. However I was only able to load all pages (visibly in the front end) when you selected to view in full screen and even then you have to use the browser print instead of the typical pdf print button.

Any snippets to get me started would be appreciated.

  • those are two questions instead of one, and neither of them is actually specific to wordpress. – Mark Kaplun Jul 13 '17 at 18:53
  • I apologize however both inquires are for the same issue so I thought it would be best to group them together. The reason I inquired on WordPress stackexchange as opposed to the general one is as I mentioned am currently trying to perform this within wordpress and am currently using wordpress page templates to perform the watermark action. Should I remove this and add it somewhere else? – DigitalDesigner Jul 13 '17 at 18:57
  • The Stack Exchange format is built around a question having only one question. – Pekka Jul 13 '17 at 19:07
  • Please note that "how do I do this in WordPress" is usually considered to be just context. If you would face exactly same issue without WP involved then it's likely not in scope here. – Rarst Jul 26 '17 at 12:35
  • Hi Rarst, I updated the question a while ago, as you see I am specifically using a wordpress plugin which I cannot use without wordpress. I am not sure how to handle this at this point as I am not allowed to delete the question and start over so how would I go about rectifying this question to get better assistance? – DigitalDesigner Jul 29 '17 at 19:25

Unless you embed the watermark in the PDF itself, people will be able to save or print without the watermark. Visitors savvy enough to know where their cache folder is can just grab the original PDF from there.

Adding a watermark to a PDF isn't a WordPress-specific question, and will require some custom PHP coding on your part unless you want to try the WooCommerce add-on from the other answer, which would also require that you actually sell the PDF to each user.

There is an excellent library called FPDF which can read in your PDF file, then dynamically embed a watermark for each user - perhaps you'd want to add their IP address, in addition to their username and the date. I have used FPDF with a WordPress install where my client was selling online training, and FPDF was used to generate official certificates of completion once the client passed the exam. It included the date the exam was passed, along with their contact and license info. You would probably want to set up a Page Template and inside that template, call FPDF to open the source PDF (which you'd save outside of webroot, so only PHP can access it, not visitors) and embed the watermark, then output in an embed or object tag so they could also view it in the WP Page.

  • 1
    thanks @WebElaine I am aware that if the user really wants the file they will be able to get it however I am being told by the boss that I still have to do it. I am sure we all have been there lol I am going to look into the waterwoo option as I do have a ecommerce solution with woocommerce already setup, I could just sell the pdfs free of charge allowing better tracking of the items as well possibly. fingers crossed :) – DigitalDesigner Jul 13 '17 at 19:26

You will need to do the watermark embedding on server side.

PDFs live in their own space that you will not be able to manipulate using CSS.

When you print a PDF, that too is normally done by the PDF plugin, not in the context of the HTML document.

To find solutions for that, I'd Google php add watermark to pdf - but apparently there exists a Wordpress/Woocommerce plugin for this also: WaterWoo.

It may be what you need.

  • thx @Pekka this may just save me a lot of time and stress. will look into it right away. – DigitalDesigner Jul 13 '17 at 19:27
  • WaterWoo is only for downloadable WooCommerce products. If you're looking to add watermarks in your media library, this solution won't work. – wp-overwatch.com Nov 22 '17 at 3:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.