Hi: 

Well, I found some references and wrote some code.  My only dilemma is, I
cannot see the text string anywhere in my PDF.  Do I need something special
to be able to add this.  Right now, I am referencing an existing PDF and
creating a new one.  Do I need some kind of PDF editing software for this to
work? 

Thanks! 


    Public Shared Sub AddWatermarkText(ByVal sourceFile As String, ByVal
outputFile As String, ByVal watermarkText As String) 
        Dim reader As iTextSharp.text.pdf.PdfReader = Nothing 
        Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing 
        Dim gstate As iTextSharp.text.pdf.PdfGState = Nothing 
        Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing 
        Dim rect As iTextSharp.text.Rectangle = Nothing 
        Dim pageCount As Integer = 0 

        reader = New iTextSharp.text.pdf.PdfReader(sourceFile) 
        rect = reader.GetPageSizeWithRotation(1) 
        stamper = New iTextSharp.text.pdf.PdfStamper(reader, New
System.IO.FileStream(outputFile, IO.FileMode.Create)) 
        gstate = New iTextSharp.text.pdf.PdfGState() 
        gstate.FillOpacity = 0.3F 
        gstate.StrokeOpacity = 0.3F 
        pageCount = reader.NumberOfPages() 
        Dim watermarkFont As iTextSharp.text.pdf.BaseFont =
iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.COURIER_BOLD,
iTextSharp.text.pdf.BaseFont.CP1252,
iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED) 
        For I As Integer = 1 To pageCount 
            underContent = stamper.GetUnderContent(1) 
            With underContent 
                .SaveState() 
                .SetGState(gstate) 
                .SetColorFill(iTextSharp.text.BaseColor.ORANGE) 
                .BeginText() 
                .SetFontAndSize(watermarkFont, 20) 
                .SetTextMatrix(30, 30) 
                .ShowTextAligned(iTextSharp.text.Element.ALIGN_BOTTOM,
watermarkText, rect.Width / 2, rect.Height / 2, 45.0F) 
                .EndText() 
                .RestoreState() 

                MessageBox.Show(watermarkText) 

            End With 

        Next 

        stamper.Close() 
        reader.Close() 

    End Sub


-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Adding-a-footer-to-a-PDF-file-tp3047529p3047529.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to