通过内存流内容写pdf而不是写 [英] write pdf through memory stream content not writing

查看:93
本文介绍了通过内存流内容写pdf而不是写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.SMALL_PAPERBACK, 10, 10, 42, 35);
iTextSharp.text.pdf.PdfWriter wri1 = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, memStream);
doc.Open();//Open Document to write
iTextSharp.text.Paragraph paragraph1 = new iTextSharp.text.Paragraph("memStream.EndWrite()");

iTextSharp.text.Phrase pharse = new iTextSharp.text.Phrase("This is my second line using Pharse.");
iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(" This is my third line using Chunk.");

doc.Add(paragraph1);

//doc.Add(pharse);

//doc.Add(chunk);
doc.Close();

byte[] content = memStream.ToArray();

// Write out PDF from memory stream. 
using (FileStream fs = File.Create("D:\\Test.pdf"))
{
	fs.Write(content, 0, (int)content.Length);
}

推荐答案

这只是猜测,但根据您提供的信息,我能做的最好:



尝试将
This is only a guess, but based on the information that you have given it's the best I can do:

Try putting
doc.Close();

放在

Using
{
   ...
}

你在哪里写文件。



关闭文件可能会也可能不会处理内存流?!?!?

where you write the file.

Closing the document might or might not dispose of the memory stream?!?!?


这篇关于通过内存流内容写pdf而不是写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆