I am facing a problem adding text to an existing an Acrobat 9 PDF file. The
text is added but is not visible. Here is the code snippet.

try
{
strFileName = System.AppDomain.CurrentDomain.BaseDirectory+
@"\updatefolder\" + strFileName;
PdfReader reader = new PdfReader(strFileName);

//
// PDFStamper is the class we use from iTextSharp to alter an existing PDF.
//
string _tempFile = AppDomain.CurrentDomain.BaseDirectory + "temp.pdf";
if (File.Exists(_tempFile))
{
File.Delete(_tempFile);
}

PdfStamper pdfStamper = new PdfStamper(reader,new
FileStream(_tempFile,FileMode.CreateNew,FileAccess.Write));

iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(1);

//
// Gets the content ABOVE the PDF, Another option is GetUnderContent(...)
// which will place the text below the PDF content.
//
PdfContentByte pdfPageContents = pdfStamper.GetUnderContent(1);
pdfPageContents.BeginText(); // Start working with text.

//
// Create a font to work with
//
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD,
Encoding.ASCII.EncodingName, false);
pdfPageContents.SetFontAndSize(baseFont,  ; // 40 point font
// pdfPageContents.SetRGBColorFill(0,0,0); // Sets the color of the font,
RED in this instance
pdfPageContents.SetColorFill(iTextSharp.text.Color.BLUE); // Sets the color
of the font, RED in this instance

pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _signatureText,
pageSize.Width-200,
pageSize.Height-50,
0);

pdfPageContents.EndText(); // Done working with text

pdfStamper.FormFlattening = false; // enable this if you want the PDF
flattened.
reader.Close();
pdfStamper.Close(); // Always close the stamper or you'll have a 0 byte
stream. 

File.Delete(strFileName);
File.Move(_tempFile,strFileName);
}
catch(Exception ex)
{
utils.WriteToLog("Failed to add signature to " + strFileName +" :: " +
ex.Message.ToString(),ex.Message,"");
}

As there is not option to upload an attachment, I cant show the output pdf
file. The code works fine with Acrobat 7 pdf files.

It would be really helpful if anyone can help me with this problem.

Thanks... 


-- 
View this message in context: 
http://www.nabble.com/Add-Text-problem-with-Acrobat-9-files-tp21012135p21012135.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to