PDFSHARP MIGRADOC将生成的位图添加到表单元格



我想使用pdfsharp和migradoc生成pdfs。至于现在,一切都很好。

现在,我想出了一个在运行时创建位图并将其添加到我的表单元格中的想法。

我已经读到,可以从资源中添加位图,因此可以在硬盘上添加它们。

请参阅:http://www.pdfsharp.net/wiki/migradoc_filelessimages.ashx

这是我尝试将其改编成我的小项目:

用于创建位图的代码:

Bitmap GreenDot = new Bitmap(32,32);
Graphics GreenDotGraphics = Graphics.FromImage(GreenDot);
GreenDotGraphics.FillEllipse(Brushes.Green,0,0,32,32);
//The next step will be converting the Bitmap to an byte[]
var byteGreenDot = ImageToByte(GreenDot);
//Now converting it to string as seen in the WikiPage
string stringGreenDot = Convert.ToBase64String(byteGreenDot);
string FinalGreenDot = "base64:"+ stringGreenDot;
//Now creating a table
.
.
.
cell = MyRow.Cell[1];
cell.AddImage(FinalGreenDot);
.
.
.

用于将位图转换为字节[]

的代码
public static byte[] ImageToByte(System.Drawing.Image img)
{
    using(var ms = new MemoryStream())
    {
        img.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
        return ms.ToArray();
    }
}

在运行代码时,我会收到警告,说"警告:图像'base64:qk02e [...] =='找不到。"(为此帖子截断了基本64字符串)。

我想我不正确将其转换为字节[]。

有人可以让我走上正确的轨道吗?

请注意,您正在使用1.50版引入的功能。

使用版本1.32或更早时,您会收到您提及的警告。

使用1.50 Beta 2或更高版本时,您的代码可按预期工作。

最新更新