Results 1 to 34 of 34

Thread: [VB.Net] Add watermark to existing Pdf file using iTextSharp

  1. #1

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    [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:
    1. ''' <summary>
    2.     ''' Add and image as the watermark on each page of the source pdf to create a new pdf with watermark
    3.     ''' </summary>
    4.     ''' <param name="sourceFile">the full path to the source pdf</param>
    5.     ''' <param name="outputFile">the full path where the watermarked pdf will be saved to</param>
    6.     ''' <param name="watermarkImage">the full path to the image file to use as the watermark</param>
    7.     ''' <remarks>The watermark image will be align in the center of each page</remarks>
    8.     Public Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)
    9.         Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
    10.         Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing
    11.         Dim img As iTextSharp.text.Image = Nothing
    12.         Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
    13.         Dim rect As iTextSharp.text.Rectangle = Nothing
    14.         Dim X, Y As Single
    15.         Dim pageCount As Integer = 0
    16.         Try
    17.             reader = New iTextSharp.text.pdf.PdfReader(sourceFile)
    18.             rect = reader.GetPageSizeWithRotation(1)
    19.             stamper = New iTextSharp.text.pdf.PdfStamper(reader, New System.IO.FileStream(outputFile, IO.FileMode.Create))
    20.             img = iTextSharp.text.Image.GetInstance(watermarkImage)
    21.             If img.Width > rect.Width OrElse img.Height > rect.Height Then
    22.                 img.ScaleToFit(rect.Width, rect.Height)
    23.                 X = (rect.Width - img.ScaledWidth) / 2
    24.                 Y = (rect.Height - img.ScaledHeight) / 2
    25.             Else
    26.                 X = (rect.Width - img.Width) / 2
    27.                 Y = (rect.Height - img.Height) / 2
    28.             End If
    29.             img.SetAbsolutePosition(X, Y)
    30.             pageCount = reader.NumberOfPages()
    31.             For i As Integer = 1 To pageCount
    32.                 underContent = stamper.GetUnderContent(i)
    33.                 underContent.AddImage(img)
    34.             Next
    35.             stamper.Close()
    36.             reader.Close()
    37.         Catch ex As Exception
    38.             Throw ex
    39.         End Try
    40.     End Sub
    41.  
    42.     ''' <summary>
    43.     ''' Add text as the watermark to each page of the source pdf to create a new pdf with text watermark
    44.     ''' </summary>
    45.     ''' <param name="sourceFile">the full path to the source pdf file</param>
    46.     ''' <param name="outputFile">the full path where the watermarked pdf file will be saved to</param>
    47.     ''' <param name="watermarkText">the text to use as the watermark</param>
    48.     ''' <param name="watermarkFont">the font to use for the watermark. The default font is HELVETICA</param>
    49.     ''' <param name="watermarkFontSize">the size of the font. The default size is 48</param>
    50.     ''' <param name="watermarkFontColor">the color of the watermark. The default color is blue</param>
    51.     ''' <param name="watermarkFontOpacity">the opacity of the watermark. The default opacity is 0.3</param>
    52.     ''' <param name="watermarkRotation">the rotation in degree of the watermark. The default rotation is 45 degree</param>
    53.     ''' <remarks></remarks>
    54.     Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkText As String, _
    55.                                        Optional ByVal watermarkFont As iTextSharp.text.pdf.BaseFont = Nothing, _
    56.                                        Optional ByVal watermarkFontSize As Single = 48, _
    57.                                        Optional ByVal watermarkFontColor As iTextSharp.text.Color = Nothing, _
    58.                                        Optional ByVal watermarkFontOpacity As Single = 0.3F, _
    59.                                        Optional ByVal watermarkRotation As Single = 45.0F)
    60.  
    61.         Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
    62.         Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing
    63.         Dim gstate As iTextSharp.text.pdf.PdfGState = Nothing
    64.         Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
    65.         Dim rect As iTextSharp.text.Rectangle = Nothing
    66.  
    67.         Dim pageCount As Integer = 0
    68.         Try
    69.             reader = New iTextSharp.text.pdf.PdfReader(sourceFile)
    70.             rect = reader.GetPageSizeWithRotation(1)
    71.             stamper = New iTextSharp.text.pdf.PdfStamper(reader, New System.IO.FileStream(outputFile, IO.FileMode.Create))
    72.             If watermarkFont Is Nothing Then
    73.                 watermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, _
    74.                                                               iTextSharp.text.pdf.BaseFont.CP1252, _
    75.                                                               iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED)
    76.             End If
    77.             If watermarkFontColor Is Nothing Then
    78.                 watermarkFontColor = iTextSharp.text.Color.BLUE
    79.             End If
    80.             gstate = New iTextSharp.text.pdf.PdfGState()
    81.             gstate.FillOpacity = watermarkFontOpacity
    82.             gstate.StrokeOpacity = watermarkFontOpacity
    83.             pageCount = reader.NumberOfPages()
    84.             For i As Integer = 1 To pageCount
    85.                 underContent = stamper.GetUnderContent(i)
    86.                 With underContent
    87.                     .SaveState()
    88.                     .SetGState(gstate)
    89.                     .SetColorFill(watermarkFontColor)
    90.                     .BeginText()
    91.                     .SetFontAndSize(watermarkFont, watermarkFontSize)
    92.                     .SetTextMatrix(30, 30)
    93.                     .ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, watermarkRotation)
    94.                     .EndText()
    95.                     .RestoreState()
    96.                 End With
    97.             Next
    98.             stamper.Close()
    99.             reader.Close()
    100.         Catch ex As Exception
    101.             Throw ex
    102.         End Try
    103.     End Sub
    Last edited by stanav; Apr 21st, 2008 at 08:24 AM.

  2. #2

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    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:
    1. ''' <summary>
    2.     ''' Add text as the watermark to each page of the source pdf to create a new pdf with text watermark
    3.     ''' </summary>
    4.     ''' <param name="sourceFile">the full path to the source pdf file</param>
    5.     ''' <param name="outputFile">the full path where the watermarked pdf file will be saved to</param>
    6.     ''' <param name="watermarkText">the string array conntaining the text to use as the watermark. Each element is treated as a line in the watermark</param>
    7.     ''' <param name="watermarkFont">the font to use for the watermark. The default font is HELVETICA</param>
    8.     ''' <param name="watermarkFontSize">the size of the font. The default size is 48</param>
    9.     ''' <param name="watermarkFontColor">the color of the watermark. The default color is blue</param>
    10.     ''' <param name="watermarkFontOpacity">the opacity of the watermark. The default opacity is 0.3</param>
    11.     ''' <param name="watermarkRotation">the rotation in degree of the watermark. The default rotation is 45 degree</param>
    12.     ''' <remarks></remarks>
    13.     Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkText() As String, _
    14.                                        Optional ByVal watermarkFont As iTextSharp.text.pdf.BaseFont = Nothing, _
    15.                                        Optional ByVal watermarkFontSize As Single = 48, _
    16.                                        Optional ByVal watermarkFontColor As iTextSharp.text.Color = Nothing, _
    17.                                        Optional ByVal watermarkFontOpacity As Single = 0.3F, _
    18.                                        Optional ByVal watermarkRotation As Single = 45.0F)
    19.  
    20.         Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
    21.         Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing
    22.         Dim gstate As iTextSharp.text.pdf.PdfGState = Nothing
    23.         Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
    24.         Dim rect As iTextSharp.text.Rectangle = Nothing
    25.         Dim currentY As Single = 0.0F
    26.         Dim offset As Single = 0.0F
    27.         Dim pageCount As Integer = 0
    28.         Try
    29.             reader = New iTextSharp.text.pdf.PdfReader(sourceFile)
    30.             rect = reader.GetPageSizeWithRotation(1)
    31.             stamper = New iTextSharp.text.pdf.PdfStamper(reader, New System.IO.FileStream(outputFile, IO.FileMode.Create))
    32.             If watermarkFont Is Nothing Then
    33.                 watermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, _
    34.                                                               iTextSharp.text.pdf.BaseFont.CP1252, _
    35.                                                               iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED)
    36.             End If
    37.             If watermarkFontColor Is Nothing Then
    38.                 watermarkFontColor = iTextSharp.text.Color.BLUE
    39.             End If
    40.             gstate = New iTextSharp.text.pdf.PdfGState()
    41.             gstate.FillOpacity = watermarkFontOpacity
    42.             gstate.StrokeOpacity = watermarkFontOpacity
    43.             pageCount = reader.NumberOfPages()
    44.             For i As Integer = 1 To pageCount
    45.                 underContent = stamper.GetOverContent(i)
    46.                 With underContent
    47.                     .SaveState()
    48.                     .SetGState(gstate)
    49.                     .SetColorFill(watermarkFontColor)
    50.                     .BeginText()
    51.                     .SetFontAndSize(watermarkFont, watermarkFontSize)
    52.                     .SetTextMatrix(30, 30)
    53.                     If watermarkText.Length > 1 Then
    54.                         currentY = (rect.Height / 2) + ((watermarkFontSize * watermarkText.Length) / 2)
    55.                     Else
    56.                         currentY = (rect.Height / 2)
    57.                     End If
    58.                     For j As Integer = 0 To watermarkText.Length - 1
    59.                         If j > 0 Then
    60.                             offset = (j * watermarkFontSize) + (watermarkFontSize / 4) * j
    61.                         Else
    62.                             offset = 0.0F
    63.                         End If
    64.                         .ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, watermarkText(j), rect.Width / 2, currentY - offset, watermarkRotation)
    65.                     Next
    66.                     .EndText()
    67.                     .RestoreState()
    68.                 End With
    69.             Next
    70.             stamper.Close()
    71.             reader.Close()
    72.         Catch ex As Exception
    73.             Throw ex
    74.         End Try
    75.     End Sub

  3. #3
    New Member
    Join Date
    May 2008
    Posts
    2

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Thanks for the code. I'm very new to iTextSHarp.

  4. #4
    New Member
    Join Date
    May 2008
    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. #5

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by WrongWayRookie
    How do I get CRLF in to the document? All of the code is on a single line.

    Thanks for your help
    Use the overloaded AddWatermrtkText sub in post #2 which you pass in a string array instead of a single string. Each element in your string array will be rendered as a line in the watermark.

  6. #6
    New Member
    Join Date
    Jul 2008
    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. #7

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    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. #8
    New Member
    Join Date
    Jul 2008
    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. #9

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by anwar_khan
    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
    That's beyond the scope of this thread. You should post your question in asp.net forum... However, you might have to reconsider your logics. When you show a non-watermarked pdf to the user, the user can just print that version (using the print button in Adobe Reader) or save it to their computer instead of clicking on your print button to print a watermarked pdf.
    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. #10
    New Member
    Join Date
    Aug 2009
    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. #11

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by pessi View Post
    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
    Nice website... Keep up the good work
    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. #12
    New Member
    Join Date
    Aug 2009
    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. #13
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Question Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    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. #14

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by BigJRofC View Post
    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
    Yes, in the code I posted, the water mark is written to the over content of the page... This will ensure that the water mark will always be visible (even when the page contains an image, for example). If your page contains mostly text, it is recommended to put the water mark on the under content of the page instead. All you have to do is changing this line:
    Code:
    underContent = stamper.GetOverContent(i)
    To this
    Code:
    underContent = stamper.GetUnderContent(i)
    The rest of the code remains unchanged.
    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. #15
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Thanks, Stanav. This is great...

  16. #16
    New Member
    Join Date
    Oct 2009
    Posts
    2

    Cool Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    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:
    1. public static void AddWatermarkTextC(string sourceFile, string outputFile, string[] watermarkText)
    2.   {
    3.     iTextSharp.text.pdf.BaseFont tWatermarkFont = null;
    4.     float tWatermarkFontSize = 48F;
    5.     iTextSharp.text.Color tWatermarkFontColor = null;
    6.     float tWatermarkFontOpacity = 0.3F;
    7.     float tWatermarkRotation = 45.0F;
    8.  
    9.     tWatermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
    10.     tWatermarkFontColor = iTextSharp.text.Color.BLUE;
    11.     AddWatermarkTextC(sourceFile, outputFile, watermarkText, tWatermarkFont, tWatermarkFontSize, tWatermarkFontColor, tWatermarkFontOpacity, tWatermarkRotation);
    12.   }//void AddWatermarkTextC(string sourceFile, string outputFile, string[] watermarkText )
    13.  
    14.  
    15.   public static void AddWatermarkTextC(string sourceFile, string outputFile, string[] watermarkText, iTextSharp.text.pdf.BaseFont watermarkFont, float watermarkFontSize, iTextSharp.text.Color watermarkFontColor, float watermarkFontOpacity, float watermarkRotation)
    16.   {
    17.  
    18.     iTextSharp.text.pdf.PdfReader reader = null;
    19.     iTextSharp.text.pdf.PdfStamper stamper = null;
    20.     iTextSharp.text.pdf.PdfGState gstate = null;
    21.     iTextSharp.text.pdf.PdfContentByte underContent = null;
    22.     iTextSharp.text.Rectangle rect = null;
    23.     float currentY = 0.0F;
    24.     float offset = 0.0F;
    25.     int pageCount = 0;
    26.  
    27.     try
    28.     {
    29.       reader = new iTextSharp.text.pdf.PdfReader(sourceFile);
    30.       rect = reader.GetPageSizeWithRotation(1);
    31.       stamper = new iTextSharp.text.pdf.PdfStamper(reader, new System.IO.FileStream(outputFile, System.IO.FileMode.Create));
    32.       if (watermarkFont == null)
    33.       {
    34.         watermarkFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
    35.       }//if (watermarkFont == null)
    36.  
    37.       if (watermarkFontColor == null)
    38.       {
    39.         watermarkFontColor = iTextSharp.text.Color.BLUE;
    40.       }//if (watermarkFontColor == null)
    41.  
    42.       gstate = new iTextSharp.text.pdf.PdfGState();
    43.       gstate.FillOpacity = watermarkFontOpacity;
    44.       gstate.StrokeOpacity = watermarkFontOpacity;
    45.       pageCount = reader.NumberOfPages;
    46.       for (int i = 1; i <= pageCount; i++)
    47.       {
    48.         underContent = stamper.GetOverContent(i);
    49.         underContent.SaveState();
    50.         underContent.SetGState(gstate);
    51.         underContent.SetColorFill(watermarkFontColor);
    52.         underContent.BeginText();
    53.         underContent.SetFontAndSize(watermarkFont, watermarkFontSize);
    54.         underContent.SetTextMatrix(30, 30);
    55.         if (watermarkText.Length > 1)
    56.         {
    57.           currentY = (rect.Height / 2) + ((watermarkFontSize * watermarkText.Length) / 2);
    58.         }//if (watermarkText.Length > 1)
    59.         else
    60.         {
    61.           currentY = (rect.Height / 2);
    62.         }//else if (watermarkText.Length > 1)
    63.  
    64.         for (int j = 0; j < watermarkText.Length; j++)
    65.         {
    66.           if (j > 0)
    67.           {
    68.             offset = (j * watermarkFontSize) + (watermarkFontSize / 4) * j;
    69.           }//if (j > 0)
    70.           else
    71.           {
    72.             offset = 0.0F;
    73.           }//else if (j > 0)
    74.  
    75.           underContent.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, watermarkText[j], rect.Width / 2, currentY - offset, watermarkRotation);
    76.         }//for (int j = 0; j < watermarkText.Length; j++)
    77.  
    78.         underContent.EndText();
    79.         underContent.RestoreState();
    80.       }//for (int i = 1; i <= pageCount; i++)
    81.  
    82.       stamper.Close();
    83.       reader.Close();
    84.     }
    85.     catch (Exception ex)
    86.     {
    87.       throw ex;
    88.     }
    89.   }//void AddWatermarkTextC(string sourceFile, string outputFile, string[] watermarkText, iTextSharp.text.pdf.BaseFont watermarkFont, float watermarkFontSize, iTextSharp.text.Color watermarkFontColor, float watermarkFontOpacity, float watermarkRotation)

    Signed,

    MacSpudster / GNoter
    ==
    ASPX = Apple Simply Performs eXcellently
    Last edited by gnoter; Oct 8th, 2009 at 05:30 PM.

  17. #17
    New Member
    Join Date
    Sep 2009
    Posts
    8

    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. #18
    New Member
    Join Date
    Oct 2009
    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. #19
    New Member
    Join Date
    Sep 2009
    Posts
    8

    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. #20
    New Member
    Join Date
    Oct 2009
    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. #21
    New Member
    Join Date
    Oct 2009
    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. #22
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Thumbs up Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by slow&steady View Post
    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
    May be my project will helpful to you : http://www.softpedia.com/get/Office-...xploiter.shtml

    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. #23
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    well done

  24. #24
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Hi Everyone,

    I have a project the will place a watermark in existing PDF file. I want to use the code of Stanav unfortunately I think I can't use it.

    What I want to do is use the Agaramond-Pro font for the text and the data that I'm going to insert has italic data in between of the normal text? Can we use the chunk function in watermark (e.g. Sample is italic data)?


    Thanks and Regards,
    BigJRofC

  25. #25
    New Member
    Join Date
    Aug 2011
    Posts
    1

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    hi everyone , can you post the sample project using this code.
    Please post the link were i can download the sample project for this topic.

    thanks and more power.

  26. #26
    New Member
    Join Date
    Dec 2011
    Posts
    1

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Thanks a lot Stanav !!!!
    I was looking for this solution since a long time.
    I have used the watermark code to display page number in the existing pdf files.
    Thanks to noter also for converting the code to C#.
    Thanks once again Stanav... G

  27. #27
    New Member
    Join Date
    Jul 2012
    Posts
    2

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    This has been soooo helpful in a project that I've been working on.

    One question though, is it possible to move the stamp so that it's not right in the center of the page?

  28. #28
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Hi Anyone,

    How could I put greek data in watermark? See below data in bold data

    ...en über sampleμrbeit

    Thanks,

    BigJRofC
    Last edited by BigJRofC; Jan 22nd, 2013 at 12:49 AM.

  29. #29
    New Member
    Join Date
    Feb 2013
    Posts
    1

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Hi Everybody,

    I pasted the code in my VB-Project. But i got an error with the description "The typ iTextSharp.text.Color is not defined".

    I did not change the code from stanav. What should i do?

    Thanks

    hasan_0034

  30. #30

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by hasan_0034 View Post
    Hi Everybody,

    I pasted the code in my VB-Project. But i got an error with the description "The typ iTextSharp.text.Color is not defined".

    I did not change the code from stanav. What should i do?

    Thanks

    hasan_0034
    You need to download iTextSharp from the Internet and then add a reference to iTextSharp.dll to your project. If you don't know how to do that, post a question in VB.Net forums and others will guide you.
    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 -

  31. #31
    New Member mestrini's Avatar
    Join Date
    Sep 2006
    Posts
    5

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    @stanav

    What about a watermark that shows up only when printing?

    I've been looking around the web for several days for a way to add a "Show when printing" watermark to a PDF file as in Adobe Acrobat 9 "Appearance Options" and haven't had any luck even to know if it's implemented or not.

  32. #32
    New Member
    Join Date
    Sep 2009
    Posts
    8

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Hi Evryone, Where I could get the link to get the c# version of pdfmanipulation.cs using the itextsharp 4? Thanks

  33. #33

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by BigJRofC View Post
    Hi Evryone, Where I could get the link to get the c# version of pdfmanipulation.cs using the itextsharp 4? Thanks
    You can always use a VB to C# converter. This one, for example:
    http://www.developerfusion.com/tools.../vb-to-csharp/
    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 -

  34. #34
    New Member mestrini's Avatar
    Join Date
    Sep 2006
    Posts
    5

    Re: [VB.Net] Add watermark to existing Pdf file using iTextSharp

    Quote Originally Posted by mestrini View Post
    @stanav

    What about a watermark that shows up only when printing?

    I've been looking around the web for several days for a way to add a "Show when printing" watermark to a PDF file as in Adobe Acrobat 9 "Appearance Options" and haven't had any luck even to know if it's implemented or not.

    Done it by myself.

    Even if not replying my request, at least I thank you for posting your code that got me started.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width