(no subject)
- From: "Paulo Soares" <psoares (at) consiste.pt>
- Date: Mon, 4 Dec 2006 21:50:46 -0000
Setting the mstream pointer to zero before reading will help.
Paulo
----- Original Message -----
From: "Paul S. Kemp" <paul (at) kbtech.co.uk>
To: <itext-questions (at) lists.sourceforge.net>
Sent: Monday, December 04, 2006 5:08 PM
Subject: [iText-questions] (no subject)
Hi,
I have a memorystream that contains a pdf document that's been amended.
I now want to place this into a pdfwriter to make some other amendments,
but i keep getting an error, so i want to check i can do this.
I first load in a PDF and then update some form fields and store that in
a memory stream. I then open a PDF writer and pdfreader, the pdfreader
points at the memorystream i want to load in and add some more content
such as a table etc,
How can i achieve this, also is this the best way of achiveing this?
I started with the following but it errors on the following line:-
PdfReader reader = new PdfReader(mstream);
Here is my code.
string sSource = HttpContext.Current.Server.MapPath("~/" +
"report.pdf");
MemoryStream mstream = new MemoryStream();
PdfReader pdfSource = new PdfReader(sSource);
PdfStamper pdfDest = new PdfStamper(pdfSource, mstream);
AcroFields aFields = pdfDest.AcroFields;
pdfDest.Writer.CloseStream = false;
// Update some form fields
pdfDest.FormFlattening = true;
pdfDest.Close();
pdfSource.Close();
// add table to document
Document doc = new Document();
MemoryStream mstream1 = new MemoryStream();
PdfReader reader = new PdfReader(mstream);
PdfWriter writer = PdfWriter.GetInstance(doc, mstream1);
writer.CloseStream = false;
doc.Open();
// Add in existing content
PdfContentByte cb = writer.DirectContent;
pdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
// Add table
doc.Close();
writer.Close();
--------------------------------------------------------------------------------
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
--------------------------------------------------------------------------------
> _______________________________________________
> iText-questions mailing list
> iText-questions (at) lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/