C# 使用SelectPdf.NET将页脚PDF居中
您好,我正在使用SelectPdf for Net Core 首先,我生成一个将html内容转换为pdf的方法,然后配置我的pdf选项,最后在所有页面中添加页脚,这是可行的,但我找不到任何属性将我的页脚置于文档中心C# 使用SelectPdf.NET将页脚PDF居中,c#,pdf,.net-core,C#,Pdf,.net Core,您好,我正在使用SelectPdf for Net Core 首先,我生成一个将html内容转换为pdf的方法,然后配置我的pdf选项,最后在所有页面中添加页脚,这是可行的,但我找不到任何属性将我的页脚置于文档中心 public string _htmlStringToBase64(string htmlContent) { HtmlToPdf converter = new HtmlToPdf(); converter.Op
public string _htmlStringToBase64(string htmlContent)
{
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.DisplayFooter = true;
converter.Footer.DisplayOnFirstPage = true;
converter.Footer.DisplayOnOddPages = true;
converter.Footer.DisplayOnEvenPages = true;
converter.Footer.Height = 80;
converter.Options.MarginLeft = 20;
converter.Options.MarginRight = 20;
converter.Options.MarginBottom = 30;
converter.Options.MarginTop = 15;
//this footer options
PdfHtmlSection footerHtml = new PdfHtmlSection(ExternalResources.FooterBase64Img);
footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.ShrinkOnly;
footerHtml.CustomCSS = "text-align: center;"; //I tried that but it doesn't work
converter.Footer.Add(footerHtml);
var docPDF = converter.ConvertHtmlString(htmlContent);
MemoryStream stream = new MemoryStream();
docPDF.Save(stream);
docPDF.Close();
return Convert.ToBase64String(stream.ToArray())
}
正如我所说,页脚展开没有问题,但我需要将其居中PdfHtmlSection类的构造函数有几个重载,其中一个重载允许图像的X、Y轴和url。 您可以尝试为水平对齐的X轴指定一个值,您可以尝试以下代码:
PdfHtmlSection footerHtml = new PdfHtmlSection(100, 0,ExternalResources.FooterBase64Img);
其中,100值是从左侧开始的位置偏移
下一个url显示所有属性:谢谢兄弟!!这对我有用