在内存中,而不是物理文件创建PDF [英] Create PDF in memory instead of physical file
本文介绍了在内存中,而不是物理文件创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何酮使用iTextSharp的创建PDF的MemoryStream,而不是物理文件。
在code以下是创建实际的PDF文件。
相反,我怎么可以创建一个byte [],并将其存储在字节[],这样我可以通过一个函数返回它
使用iTextSharp.text;
使用iTextSharp.text.pdf;
文档的文档=新文件(iTextSharp.text.PageSize.LETTER,10,10,42,35);
PdfWriter WRI = PdfWriter.GetInstance(文件,新的FileStream(C:\\\\ Test11.pdf,FileMode.Create));
doc.Open(); //打开文档编写
逐段=新段(这是用我的段落首行);
短语pharse =新词(这是我用Pharse第二行。);
大块大块=新的块(这是用大块我第三行。);doc.Add(款);doc.Add(pharse);doc.Add(块);
doc.Close(); //关闭文件
解决方案
开关与一个MemoryStream的FILESTREAM。
MemoryStream的memStream =新的MemoryStream();
PdfWriter WRI = PdfWriter.GetInstance(DOC,memStream);
...
返回memStream.ToArray();
How do one create PDF in memorystream instead of physical file using itextsharp.
The code below is creating actual pdf file.
Instead how can I create a byte[] and store it in the byte[] so that I can return it through a function
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
解决方案
Switch the filestream with a memorystream.
MemoryStream memStream = new MemoryStream();
PdfWriter wri = PdfWriter.GetInstance(doc, memStream);
...
return memStream.ToArray();
这篇关于在内存中,而不是物理文件创建PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文