Hello,
I am using iTextSharp and have run into a rather weird problem that I was
hoping someone would be able to help me with...
Right now, I have a process which takes a PDF, adds a few bits of text to
it, and then saves it as a new PDF. The output PDF looks fine, but
something is incomplete or corrupt with it. If I open it in Acrobat, and do
nothing at all but immediately close Acrobat, I'm asked to save the changes.
At first I wrote this off as weird Acrobat behavior, but then I noticed that
if I took my output PDF, and tried to read a page from it using PdfReader
and then add that page to a new document using PdfContentByte.AddTemplate,
everything would appear to work (no exceptions thrown), but the resulting
PDF was corrupt to the point Acrobat wouldn't even open it.
This is a quick snippet to show what I'm doing:
---------
#region first section
PdfReader pdfr_page = new PdfReader("log-template.pdf");
Document _pdf = new Document(pdfr_page.GetPageSize(1));
PdfWriter writer = PdfWriter.GetInstance(_pdf, new FileStream("log-" +
this.ID.ToString() + ".pdf", FileMode.OpenOrCreate, FileAccess.Write,
FileShare.None));
writer.CloseStream = true;
_pdf.Open();
PdfContentByte content = writer.DirectContent;
_pdf.NewPage();
content.AddTemplate(writer.GetImportedPage(pdfr_page, 1), 0, 0);
foreach (Token t in this.Tokens)
{
content.BeginText();
//a handful of content.ShowTextAligned calls made here
content.EndText();
}
_pdf.NewPage();
content.AddTemplate(writer.GetImportedPage(pdfr_page, 2), 0, 0);
_pdf.NewPage();
content.AddTemplate(writer.GetImportedPage(pdfr_page, 3), 0, 0);
pdfr_page.Close();
_pdf.Close();
#endregion
#region second section
pdfr_page = new PdfReader("log-" + this.ID.ToString() + ".pdf");
_pdf = new Document(pdfr_page.GetPageSize(1));
writer = PdfWriter.GetInstance(_pdf, new FileStream("log-alt-" +
this.ID.ToString() + ".pdf", FileMode.Create, FileAccess.Write,
FileShare.None));
writer.CloseStream = true;
_pdf.Open();
content = writer.DirectContent;
_pdf.NewPage();
content.AddTemplate(writer.GetImportedPage(pdfr_page, 1), 0, 0);
pdfr_page.Close();
_pdf.Close();
#endregion
---------
So what happens is that the first "log-" file is generated, and opens fine
in Acrobat (and everything else), but causes Acrobat to prompt to save
changes even though none have been made. Also, in the second section, the
"log-alt-" file that I try to create based on the first "log-" file comes
out corrupted or incomplete to the point that Acrobat won't even open it.
Thanks in advanced for any help/guidance you can provide! :-)
Pat
--
View this message in context:
http://www.nabble.com/Incomplete-or-corrupted-PDF-output-tp23418677p23418677.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/