我正试图将itextsharp生成的pdf文件保存到数据库中。但是,到目前为止我还没有成功。
我正在使用LINQtoSQL。
代码如下:
MemoryStream ms = new MemoryStream();
Document d = new Document(PageSize.A4, 60, 60, 40, 40);
PdfWriter w = PdfWriter.GetInstance(d, ms);
w.CloseStream = false;
string txtTemplate = "";
Encoding en = Encoding.GetEncoding("iso-8859-1");
StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/Content/templates/CessaoDireitosDica.txt"), en);
txtTemplate = sr.ReadToEnd();
sr.Close();
string conselhos = "";
Font font = new Font(Font.HELVETICA, 11, Font.NORMAL);
font.SetColor(0xC6, 0xC6, 0xC6);
Paragraph txtBody = new Paragraph(txtTemplate, font);
txtBody .SetAlignment(ElementTags.ALIGN_JUSTIFIED);
d.Open();
d.Add(txtBody);
d.Close();
byte[] pdfDone = ms.ToArray();
w.Flush();
ms.Flush();
ms.Close();
return pdfDone;
我还使用这段代码动态呈现pdf(我切断字节[]pdfDone…并返回MemoryStream)。
提前谢谢!