【发布时间】:2018-07-18 17:34:28
【问题描述】:
当我使用以下代码时,它在 PDF 中没有显示图像。
这是我的代码
private static void RenderHtmlToImage(string html, Paragraph paragraph, int pageCnt)
{
System.Drawing.Image image = HtmlRender.RenderToImageGdiPlus(html);
//var tempImagefile = tempImagePath + "\\tempImage_" + pageCnt + ".png";
//image.Save(tempImagefile, ImageFormat.Png);
//paragraph.AddImage(tempImagefile);
byte[] imageArray = imageToByteArray(image);
string imageFilename = "base64:" + Convert.ToBase64String(imageArray);
paragraph.AddImage(imageFilename);
}
public static byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, ImageFormat.Png);
return ms.ToArray();
}
当我将图像保存在本地文件夹中时,它工作得非常好。
我也关注了这个链接http://www.pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx,但它对我不起作用。
【问题讨论】:
-
如果不能正常工作,请提供 MCVE 而不仅仅是代码 sn-p。