小编use*_*831的帖子

保存前将pdf转换为byte []

我正在使用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 …
Run Code Online (Sandbox Code Playgroud)

c# pdf

2
推荐指数
1
解决办法
1859
查看次数

标签 统计

c# ×1

pdf ×1