Some points:
- opacity 1 is the same as not using it. Remove the gstate unless you really
need it, it has implications in the way the page is rendered.
- ShowTextAligned(iTextSharp.text.Element.ALIGN_RIGHT, watermarkText,
rect.Width, 0, 0)
- you'll have to take into account the crop box if there's one and offset the
position to the visible area.
Paulo
________________________________
From: Steve Anderson [mailto:steve.ander...@despatch.com]
Sent: Wednesday, November 17, 2010 10:52 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] iText stamp
Hi:
I have no idea how to log in to the forum. Is it itext or itextsharp? What's
the difference. Anyhow, I did sign up and I hope I have an account. Anyhow,
there is this code below. All I want to do is place a piece of horizontal text
in the lower right corner. Apparently, this code says it is transparent and
apparently going to the wrong place.
Would there be something out there to help me know what the constants for the
commands, as well as the commands themselves mean?
Thank you.
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 = 1
gstate.StrokeOpacity = 1
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, 0)
.EndText()
.RestoreState()
Debug.WriteLine("watermarkText: " & watermarkText)
End With
Next
stamper.Close()
reader.Close()
End Sub
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão desta
mensagem não significa a perca de confidencialidade. Se esta mensagem for
recebida por engano, por favor envie-a de volta para o remetente e apague-a do
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de
usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain
confidential or legally protected information. The incorrect transmission of
this message does not mean the loss of its confidentiality. If this message is
received by mistake, please send it back to the sender and delete it from your
system immediately. It is forbidden to any person who is not the intended
receiver to use, distribute or copy any part of this message.
------------------------------------------------------------------------------
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
iText-questions@lists.sourceforge.net
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