IronPdf可以很好地转换HTML标头和主页,但是即使页眉可以将页脚拉伸到全宽,而且我使用的是相同的HTML片段。
我正在运行VS2019,IronPdf 5.2.0.1,C#。
string htmlFooter = "";
using (System.Drawing.Image img = System.Drawing.Image.FromFile(_appPath + @"\Footer01b.png"))
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, img.RawFormat);
byte[] imgB = ms.ToArray();
htmlFooter = Convert.ToBase64String(imgB);
}
}
htmlFooter = "<img style='width:100%' src='data:image/jpeg;base64," + htmlFooter + "'>";
//File.WriteAllText(_appPath + @"\HTML--" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".html", htmlFooter);
IronPdf.HtmlHeaderFooter ftr = new IronPdf.HtmlHeaderFooter();
ftr.HtmlFragment = htmlFooter;
ftr.Height = 35;
string html = quote.Description;//.Replace("\n", "");
IronPdf.PdfDocument pdf = pdfRend.RenderHtmlAsPdf(html);
pdf.MetaData.Title = title;
pdf.MetaData.Subject = title;
pdf.MetaData.Author = "QuoteMaster - (c) 2017 Mylus Systems LTD.";
pdf.AddHTMLHeaders(ftr);
pdf.AddHTMLFooters(ftr);
pdf.SaveAs(_appPath + @"\HTML--" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".pdf");
结果:
答案 0 :(得分:2)
您是否尝试过使用AddHTMLHeaders / AddHtmlFooters重载来指定所需的边距?
根据对象引用,AddHTMLHeaders和AddHTMLFooters的默认边距为25mm ...有趣的是,您发现页眉和页脚的默认边距不一致,但是重载可能会有所帮助。 / p>
https://ironpdf.com/c%23-pdf-documentation/html/M_IronPdf_PdfDocument_AddHTMLHeaders_1.htm https://ironpdf.com/c%23-pdf-documentation/html/M_IronPdf_PdfDocument_AddHTMLFooters_1.htm
pdf.AddHTMLHeaders(ftr, 0, 0, 0);
pdf.AddHTMLFooters(ftr, 0, 0, 0);