|
|
#1 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
[VB.Net] Add watermark to existing Pdf file using iTextSharp
Hello all again,
Recently, a vbforum member posted a question in VB.Net forum on how to add watermark to Pdf pages. Although I've never had to do it, but I know for sure that iTextSharp is capable of this. So I spent some spare time writing some code to do it using the free iTextSharp library, and here it is, the 2 subroutines for adding an image and text as the watermark on each page of a pdf file. Don't forget to add a reference to itextsharp.dll to your project!!! vb.net Code:
Last edited by stanav; Apr 21st, 2008 at 08:24 AM. |
|
|
|
|
|
#2 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
This is the updated subroutine for adding multiple text line watermark to pdf pages. The number of lines depending on the number of elements in the string array watermarkText() you pass in.
vb.net Code:
|
|
|
|
|
|
#3 |
|
New Member
Join Date: May 08
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Thanks for the code. I'm very new to iTextSHarp.
|
|
|
|
|
|
#4 |
|
New Member
Join Date: May 08
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
How do I get CRLF in to the document? All of the code is on a single line.
Thanks for your help
|
|
|
|
|
|
#5 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Quote:
|
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Jul 08
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
hi this really a nice code but the prob lem with i don't wanna create another file i wanna put water mark on exssiting file and dispaly it plz help how can i do this
thanks anwar khan |
|
|
|
|
|
#7 |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
The reason why you have to create another file is that when you open the original file for reading, it's being used and you can not write to it. Having said that, you can simply create a new temp file, and once done, you delete the original and rename the temp file to the original's name. This can be done with just a few lines of extra code.
__________________
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln - |
|
|
|
|
|
#8 |
|
New Member
Join Date: Jul 08
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
thanks for the reply can you give me code how can do it or basically i am doing i am showing a pdf file in asp.net page what my requirement is that when user clikc on print then the watermark put on that file and print it can we do that
thanks anwar khan Last edited by anwar_khan; Jul 18th, 2008 at 05:32 AM. |
|
|
|
|
|
#9 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Quote:
__________________
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln - |
|
|
|
|
|
|
#10 |
|
New Member
Join Date: Aug 09
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Excellent code. I use it to create an online application.
I made it in asp.net using c# http://watermark-images.com/pdf-watermark.aspx |
|
|
|
|
|
#11 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Quote:
__________________
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln - |
|
|
|
|
|
|
#12 |
|
New Member
Join Date: Aug 09
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Thank you. I am in the process of building 10 more nice applications that can be of use to lot of people.
|
|
|
|
|
|
#13 |
|
New Member
Join Date: Sep 09
Posts: 4
![]() |
This is excellent code and this is what i needed. BTW, I have question if this is possible, can the watermark appear behind page?
Thanks |
|
|
|
|
|
#14 | |
|
PowerPoster
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,309
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Quote:
Code:
underContent = stamper.GetOverContent(i) Code:
underContent = stamper.GetUnderContent(i)
__________________
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln - |
|
|
|
|
|
|
#15 |
|
New Member
Join Date: Sep 09
Posts: 4
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Thanks, Stanav. This is great...
|
|
|
|
|
|
#16 |
|
New Member
Join Date: Oct 09
Posts: 2
![]() |
For those of us who find this solution via a web search and want a C# (C-Sharp) version, here it is, tested and working.
Foremost: Major thx to stanav; excellent post. You'll note there are 2 functions, with the first functions calling the second function. This mimics the "OPTIONAL" params in VB C-Sharp Code:
Signed, MacSpudster / GNoter == ASPX = Apple Simply Performs eXcellently
Last edited by gnoter; Oct 8th, 2009 at 05:30 PM. |
|
|
|
|
|
#17 |
|
New Member
Join Date: Sep 09
Posts: 4
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Hi Stanav,
I want to use Arial 8 pt in size font base. How to change the font name? Thanks in advance. Regards, Buddy |
|
|
|
|
|
#18 |
|
New Member
Join Date: Oct 09
Posts: 2
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Buddy,
Dim MyNewFont As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontNameSTRING, FontSizeINT) where FontNameSTRING = "Arial" and FontSizeINT = 8 such as Dim Arial8Plain As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont("Arial", 8) Then use the variable Arial8Plain where you'd like. Signed, MacSpudster / GNoter == ASPX = Apple Simply Performs eXcellently
|
|
|
|
|
|
#19 |
|
New Member
Join Date: Sep 09
Posts: 4
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Thanks, MacSpudster.
What I need to do, instead of using Helvetica on the above code of Stanav I will use Arial font as a Base Font of the text in my watermark. Regards, Buddy |
|
|
|
|
|
#20 |
|
New Member
Join Date: Oct 09
Posts: 5
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
Hi
i want to get the following font "Heading 1+93 pt, Bold, Outlined, Black, Times New Roman" when i declared like below Dim TNR_93 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont("TimesNewRoman", 93) and pass it at watermarkFont like this AddWatermarkText(FileName, Path & "\" & Fname(0) & "_WTRMK." & Fname(1), Ptext, TNR_93) i am getting error like this ""Value of type 'iTextSharp.text.Font' cannot be converted 'iTextSharp.text.pdf.BaseFont'"" Please Help me its very urgent !!!!!!!!!! Thanks in advance Sri |
|
|
|
|
|
#21 |
|
New Member
Join Date: Oct 09
Posts: 5
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
One more question is
I want to watermark two lines one with fontsize 93 and other with 14 also i want to include the date on the Topleft and company logo on topright is it possible ? i tried with the above code it is overwriting , instead of having all Can anybody suggest how to do it Thanks in advance, Sri |
|
|
|
|
|
#22 | |
|
Addicted Member
Join Date: Feb 08
Location: XP & Vista
Posts: 181
![]() |
Quote:
Just take a screen shot which u want like (one with fontsize 93 and other with 14 etc) and use second option as watermark by image method and do it Hope it helpful! |
|
|
|
|
|
|
#23 |
|
Junior Member
Join Date: Dec 09
Posts: 27
![]() |
Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp
well done
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|