如何在内存流中创建PDF而不是使用itextsharp创建物理文件。在内存中创建PDF而不是物理文件
以下代码正在创建实际的pdf文件。
相反,我怎么可以创建一个byte [],并将其存储在一个字节[],这样我可以通过函数
using iTextSharp.text;
using iTextSharp.text.pdf;
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
doc.Open();//Open Document to write
Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
Phrase pharse = new Phrase("This is my second line using Pharse.");
Chunk chunk = new Chunk(" This is my third line using Chunk.");
doc.Add(paragraph);
doc.Add(pharse);
doc.Add(chunk);
doc.Close(); //Close document
PdfWriter没有实现IDisposable,所以你不能在using语句中使用它。也许这只是我正在使用的版本(5.0.5),因为我知道版本4 – musefan 2012-01-05 11:49:15
@musefan有一些类更改,是的,在5.0.5中就是这样。在当前版本5.5中,'PdfWriter'扩展了'DocWriter',它实现了'IDocListener',它扩展了'IDisposable'。我不知道什么时候IDisposable被添加到IDocListener中,但是它在5.0.5之前和5.5.0之前有一段时间。 – 2014-02-28 23:55:05