Print Page | Close Window

Add Watermark behind PDF Text

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2672
Printed Date: 22 Nov 24 at 5:29PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Add Watermark behind PDF Text
Posted By: chrisreed
Subject: Add Watermark behind PDF Text
Date Posted: 18 Jun 13 at 9:28AM
I followed the QuickPDF example on how to add a Watermark to an existing PDF Document which all worked fine, except the Watermark was inserted infront of the existing PDF text.
 
How can I insert the watermark behind the existing PDF text.
 
See link below to which shows the difference....
http://s20.postimg.org/88u3pgh71/Watermark_behind_infront_of_text.png - http://s20.postimg.org/88u3pgh71/Watermark_behind_infront_of_text.png
 
NOTE: Making the watermark semi-transparent is not the affect I am really after.
 
Chris



Replies:
Posted By: Ingo
Date Posted: 18 Jun 13 at 10:34AM
Hi Chris!
 
That's heavy stuff!
There's no sample here.
You should read about layers and (optional) content groups in the reference.
You have to recreate the whole document for this (taking the layers away... drawing the watermark... then the layers back... puuuuh :)
Nearly the same and much easier it is to put a bit more transparency to the watermark ;-)
 
Cheers, Ingo
 


Posted By: chrisreed
Date Posted: 19 Jun 13 at 2:26AM
Damn.  I was hoping there was a Method like "Appear Behind Text" or something similar.
How do I put in request for a Method like this be added to the next version as I feel it is a very useful feature for things like Watermarks.
 
As for adding more transparency I'm in a Catch-22 situation.  I have to add more transparency so I can see the text behind the watermark, but if I make it too transparent then the Watermark does not come out if the report is photocopied - maybe I can get away with a happy compromise.
 
Thanks Ingo for the reply.


Posted By: chrisreed
Date Posted: 19 Jun 13 at 5:27AM
Hi again,
There was a post that explained how to insert text behind text using Streams (see link) which I thought I could use with my Watermark issue.
 
http://www.quickpdf.org/forum/inserting-text-behind-existing-text_topic2570_post10615.html?KW=behind+text#10615 - http://www.quickpdf.org/forum/inserting-text-behind-existing-text_topic2570_post10615.html?KW=behind+text#10615
 
My original PDF seemed to have two ContentStreams and I created a NewContentStream (No. 3) added the image and then used the MoveContentStream function to move it from Stream 3 to Stream 1.  But it didn't matter what streams I moved around or where I added the image (before or after a NewStream was created) the watermark always appeared on top of the original text.
 
Can my issue be solved using ContentStreams?
 
Chris


Posted By: Ingo
Date Posted: 19 Jun 13 at 10:29AM

Can my issue be solved using ContentStreams?

Hi Chris!

That's what i told.
But you should try - seems here in the user forum there's nobody doing this before.
If you want to post new user ideas/-requests you should go onto the official pages (have a click on the logo at the top, left).
BTW: Creating a new document there's always one blank page and one layer/contentgroup.

Cheers, Ingo

 



Posted By: AndrewC
Date Posted: 20 Jun 13 at 4:22AM
You could try something along the lines of the following which I have adapted from  http://www.quickpdf.org/forum/inserting-text-behind-existing-text_topic2570_post10615.html?KW=behind+text#10615 - http://www.quickpdf.org/forum/inserting-text-behind-existing-text_topic2570_post10615.html?KW=behind+text#10615

   QP.LoadFromFile (...
   QP.SelectPage(1);
   int cs = NewContentStream();

   QP.SetOrigin(1);

   int img = QP.AddImageFromFile("myimage.png", 0);
   QP.DrawImage(0,0,QP.PageWidth(), QP.PageHeight();

   QP.MoveContentStream(cs, 1);

   QP.SaveToFile("newfile.pdf");

Moving the content stream with the image to content stream 1 will mean that the image is draw first and that any test or other logos will be drawn on top.

Whether this approach works or not will depend on how the PDF is created.  If the first command of the PDF is to draw and fill a white rectangle the same size as the page then this approach will not work.

If this doesn't work then you will need to post some code so we can understand what is and isn't working.


Andrew


Posted By: chrisreed
Date Posted: 20 Jun 13 at 7:41AM
Ha! Ha! That's the exact same link I mentioned above Tongue  My code is based on your example Andrew - it sort of worked for some PDF's but not for others (see my code below).
 
http://s20.postimg.org/opmbe9yq5/Code_to_Move_Watermark_to_Back.png - http://s20.postimg.org/opmbe9yq5/Code_to_Move_Watermark_to_Back.png
 
If I converted a Word document into a PDF using PDF Creator it worked, however if I used a PDF created from a hospital application and moved it to Stream 1, the watermark didn't even appear!!
 
If I moved it to Stream 2, the Watermark appeared in both PDF's but always infront of the text.
 
In both cases the ContentStreamCount was three.  How do I tell if the first command is to draw and fill a white rectangle - could that be the issue?
 
Unfortunately I can't attach the problematic PDF report because it has patient information on it.
 
Chris
 
 


Posted By: chrisreed
Date Posted: 24 Jun 13 at 9:21AM
As Andrew mentioned in his previous post, the reason it wasn't working was that the first command in the PDF File was to draw a white rectangle.
 
This can be found using GetPageContentToString (or GetPageContentToVariant - ActiveX version) and you will see something like this at the top of the file.
 

1 g                                   // select White -

0 2.66797 4956 7014 re // create a rectangle

f                                     // fill the rectangle with the white pen

 
And the reason for this was I was printing the PDF indirectly through a Web-based application and not directly through the PDFCreator application.
 
Chris


Posted By: mat miller
Date Posted: 01 Apr 14 at 4:38AM
I wonder can you achieve similar effect by adjusting the watermark transparency.

http://www.quickpdf.org/forum/watermark_topic230.html" rel="nofollow - http://www.quickpdf.org/forum/watermark_topic230.html
http://stackoverflow.com/questions/2913934/how-i-can-add-watermark-to-existing-pdf-file-using-php913934/use-php-how-i-can-add-" rel="nofollow - http://stackoverflow.com/questions/2913934/use-php-how-i-can-add- http://www.rasteredge.com/how-to/vb-net-imaging/pdf-watermark-creating/" rel="nofollow - watermark-to-pdf


Posted By: chrisreed
Date Posted: 01 Apr 14 at 5:24AM
Hi Mat,
Yes I did try that, but its a Catch-22 situation.  I needed to make the Watermark transparent enough so I can still see the text/images behind it, but not too transparent that the Watermark is hard to read.
 
I could not find a suitable compromise between these two conflicting requirements which is why it MUST be placed behind the text/images.
 
Chris


Posted By: lucy142
Date Posted: 24 Mar 15 at 5:33AM

 Hi Friends,

To add watermark behind pdf text you can go with this perfect PDF watermark for mac software solution to add text/image watermark to every page of a PDF file or behind PDF Text. It facilities you with the realtime preview output effect, Batch watermark PDF files like amazing features.Wink 

For any information about this software you can visit to this link:

http://www.completepdfsolultions.com/pdf-watermark-mac.php




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk