问题描述
我使用 HTML Renderer 从 HTML 生成 PDF,所有图像均来自流
var pngBinaryDatalogoLeft = File.ReadAllBytes(folderPath + "logo.png");
var ImgDataURIlogoLeft = @"data:image/png;base64," + Convert.ToBase64String(pngBinaryDatalogoLeft);
html = html.Replace("[logoLeft]",ImgDataURIlogoLeft);
var pngBinaryDataBGImg = File.ReadAllBytes(folderPath + "background.png");
var ImgDataURIBGImg = @"data:image/png;base64," + Convert.ToBase64String(pngBinaryDataBGImg);
html = html.Replace("[BGImg]",ImgDataURIBGImg);
var config = new PdfGenerateConfig();
config.PageOrientation = PageOrientation.Landscape;
config.PageSize = PdfSharpPageSize.A4;
string cssstr = File.ReadAllText(folderPath + "1.css");
CssData css = PdfGenerator.ParseStyleSheet(cssstr);
PdfSharp.Pdf.PdfDocument pdf = PdfGenerator.GeneratePdf(html,config,css);
MemoryStream stream = new MemoryStream();
pdf.Save(stream,false);
byte[] bytes = stream.ToArray();
File.WriteallBytes(folderPath + "document.pdf",bytes);
在我的 HTML 中,img 被流替换工作正常
<img class="logo-left" src="[logoLeft]" />
但是背景图片不起作用:
<body style="background: url('[BGImg]')">
我没有来自 URL 的图像,因为它来自数据库(保存为流)
XGraphics gfx = XGraphics.Frompdfpage(pdf.Pages[0]);
XImage image = XImage.FromFile(bgImgPath);
gfx.DrawImage(image,x,y,width,height);
也尝试过 iTextSharp,也无法解决。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)