bodyTable = new PdfPTable(1); 

               MemoryStream ms = new MemoryStream();

                PdfWriter pw = PdfWriter.GetInstance(document, ms);

                pw.InitialLeading = 16; //to make space for the header on each 
page

                pw.PageEvent = e;

                document.Open();

                document.Add(new PdfPTable(1)); //content

                document.Add(new PdfPTable(1)); //content

                document.Add(new PdfPTable(1));  //content

                document.Close();

                byteStream = ms.ToArray();



Paulo

  ----- Original Message ----- 
  From: Fox, David 
  To: Post all your questions about iText here 
  Sent: Wednesday, April 21, 2010 8:28 PM
  Subject: Re: [iText-questions] When can I access 
PdfWriter.DirectContentforabyte stream?


  It works with the MemoryStream, but I can’t write to file correctly. The file 
is created, looks to be about the correct size, but is always corrupt upon 
opening. Is there some other way to write to file using MemoryStream without 
FileStream? The PDF shows up as expected in my browser. Thanks!

   

  Document document = new Document(PageSize.A4, 36, 36, 36 + 189, 36);

   

                  bodyTable = new PdfPTable(1); 

                 MemoryStream ms = new MemoryStream();

                  PdfWriter pw = PdfWriter.GetInstance(document, ms);

                  pw.InitialLeading = 16; //to make space for the header on 
each page

                  pw.PageEvent = e;

                  document.Open();

                  document.Add(new PdfPTable(1)); //content

                  document.Add(new PdfPTable(1)); //content

                  document.Add(new PdfPTable(1));  //content

                  try

                  {

                      FileStream fs = new 
FileStream(@"C:\path\i\have\permission\to\write\" + stringfilename + "-1.pdf", 
FileMode.Create);

                      ms.WriteTo(fs);

                      fs.Close();

                  }

                  catch (Exception ex)

                  {

                  }

                  document.Close();

                  byteStream = ms.GetBuffer();

                  ms.Close();

   

   

  From: Paulo Soares [mailto:psoa...@glintt.com] 
  Sent: Wednesday, April 21, 2010 3:13 PM
  To: Post all your questions about iText here
  Subject: Re: [iText-questions] When can I access PdfWriter.DirectContent 
forabyte stream?

   

  Instead of a FileStream use a MemoryStream. Forget about DirectContent.

   

  Paulo

    ----- Original Message ----- 

    From: Fox, David 

    To: Post all your questions about iText here 

    Sent: Wednesday, April 21, 2010 5:46 PM

    Subject: [iText-questions] When can I access PdfWriter.DirectContent for 
abyte stream?

     

    I am trying to output a PDF using byte stream (iTextSharp 5), but the 
DirectContent member of PdfWriter is empty. Am I accessing it at the wrong 
time? This code is in the constructor of my worksheet class:

     

                Document document = new Document(PageSize.A4, 36, 36, 36 + 189, 
36);

     

                    bodyTable = new PdfPTable(1); 

                    PdfWriter pw = PdfWriter.GetInstance(document, new 
FileStream(stringname + ".pdf", FileMode.Create));

                    pw.InitialLeading = 16; //to make space for the header on 
each page

                    pw.PageEvent = e;

                    document.Open();

     

                    document.Add(new PdfPTable(1)); //content

                    document.Add(new PdfPTable(1)); //content

                    document.Add(new PdfPTable(1));  //content

     

                    byteStream = pw.DirectContent.ToPdf(pw);

     

                    document.Close();

                

          

    Thanks in advance!

 BMIC Disclaimer:  This email and any files transmitted with it are 
confidential and intendedsolely for the use of the individual or entity to whom 
they are addressed.  Ifyou have received this email in error please notify the 
system manager.  Pleasenote that any views or opinions presented in this email 
are solely those of theauthor and do not necessarily represent those of the 
company.  Finally, therecipient should check this email and any attachments for 
the presence ofviruses. The company accepts no liability for any damage caused 
by any virustransmitted by this email.
BMIC Disclaimer: 
 
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.  If
you have received this email in error please notify the system manager.  Please
note that any views or opinions presented in this email are solely those of the
author and do not necessarily represent those of the company.  Finally, the
recipient should check this email and any attachments for the presence of
viruses. The company accepts no liability for any damage caused by any virus
transmitted by this email.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
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/

Reply via email to