【发布时间】:2014-07-28 15:25:43
【问题描述】:
我正在使用 PDFSharp,我正在从位图图像创建 pdf。我可以将图像保存和查看为 pdf 没问题。但现在我想做的是在将 pdf 保存为实际文件之前,我想将其转换为 byte[]。在我保存它之后,我可以将它保存为 byte[] 。我将有两种不同的方法,一种将 pdf 保存到用户可以打开的文件中,另一种将 pdf 保存为将发送到数据库的字节,但我可能不会两者都做。我可能需要一天保存一个文件,另一天将它保存为一个字节,而无需将其保存为文件。我有什么:
public void DrawImage(Bitmap thumbnail)//thumbnail is created with another method
{
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XImage image = XImage.FromGdiPlusImage(thumbnail);
gfx.DrawImage(image, 0, 0, 612, 792);
string filename = string.Format(@"{0}.pdf", Guid.NewGuid());
//This is Save(string path), there is also a Save(memoryStream stream)
document.Save(filename);
//so before I save it as a *.PDF I would like to save it as byte[] that can be sent to a Database, and eventually read from and convert the byte to a viewable *.pdf
//This saves a Bitmap as a pdf successfully
}
我希望我是有道理的,如果需要我可以进一步解释
【问题讨论】:
-
好的,如果我这样做,我将如何获取建议的这个字节流并将其重新转换为可查看的 pdf?我看到的每个示例都使用 WriteAllBytes() 接受文件路径..