Hello,

i've created an pdf by using an template. I do it with the PdfReader and 
the PdfStamper by creating a memorystream. Sending the Stream to the 
Client works very well.
But I need to convert the memorystream to an filestream for other 
purposes (e.g. to save to local disk). How can I do that?
The code I posted below didn't work. The file is corrupt.

My Code:

             bool error;
             MemoryStream ms = new MemoryStream();
             MemoryStream ms1 = new MemoryStream();

             // read existing PDF document, optimize memory
             PdfReader reader = new PdfReader(new 
RandomAccessFileOrArray(PDFTemplate),null);
             if (reader != null)
             {
                 // add content to existing PDF document with PdfStamper
                 PdfStamper stamper = null;
                 Boolean res;

                     stamper = new PdfStamper(reader, ms);

                     if (stamper != null)
                     {
                         //Fill out Template
                         try
                         {
                             // retrieve properties of PDF form 
w/AcroFields object
                             AcroFields af = stamper.AcroFields;
                             // fill in PDF fields by parameter
                             error |= af.SetField("Field1", string1);
                             error |= af.SetField("Field2", string2);

                             // make resultant PDF read-only for end-user
                             stamper.FormFlattening = true;
                             //copy stream to ms1
                             ms.WriteTo(ms1);
                             stamper.Close();
                             reader.Close();

                             //Write to File
                             FileStream fs = File.Create("C:\\Test.pdf");
                             ms1.WriteTo(fs);
                             fs.Close();
                         }
                     }
             }

best regards

Karsten

-- 



LISA office:

fon: +49-5556-9938-0
fax: +49-5556-9938-10

mail: [email protected]
web : www.lisalaser.de

--------------------------------------------------------------------------

LISA laser products OHG
Fuhrberg&  Teichmann
Max-Planck-Str. 1
D- 37191 Katlenburg-Lindau
Germany
Amtsgericht Göttingen HRA 130261
UST-ID-Nr:DE116210331


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a 
definitive record of customers, application performance, security 
threats, fraudulent activity and more. Splunk takes this data and makes 
sense of it. Business sense. IT sense. Common sense.. 
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
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