我使用的是将EvoPDF保存到PDF文件中的文件。HTML包含长文本(可以包含列表、表等)。我想添加页边距,但我不想使用pdfConverter.PdfDocumentOptions.{Bottom/Top}Margin -属性,我想将页边距设置为HTML (类似于Microsoft,在这里设置页面大小和页边距,文本自动移动到下一页,该页面以前设置了页边距)。我预览了他们的帮助页,但我找不到这方面的信息。
我的转换代码是:
EvoPdf.HtmlToPdf.PdfConverter pdfConverter = new EvoPdf.HtmlToPdf.PdfConverter();
pdfConverter.LicenseKey = System.Configuration.ConfigurationManager.AppSettings["EvoHtmlToPdfLicence"];
pdfConverter.PdfDocumentOptions.PdfPageSize = EvoPdf.HtmlToPdf.PdfPageSize.Letter;
pdfConverter.PdfDocumentOptions.PdfPageOrientation = EvoPdf.HtmlToPdf.PdfPageOrientation.Portrait;
byte[] pdf = pdfConverter.GetPdfBytesFromHtmlString(htmlText);谢谢!
发布于 2017-05-04 14:07:39
边距属性是全局的,因此页眉、页脚、正文都受此影响。如果只想影响呈现的HTML,可以使用以下设置:
文档
代码示例:
// Category: HTML Content Destination and Spacing Options
// Set HTML content destination in PDF page
if (xLocationTextBox.Text.Length > 0)
htmlToPdfConverter.PdfDocumentOptions.X = float.Parse(xLocationTextBox.Text);
if (yLocationTextBox.Text.Length > 0)
htmlToPdfConverter.PdfDocumentOptions.Y = float.Parse(yLocationTextBox.Text);
if (contentWidthTextBox.Text.Length > 0)
htmlToPdfConverter.PdfDocumentOptions.Width = float.Parse(contentWidthTextBox.Text);
if (contentHeightTextBox.Text.Length > 0)
htmlToPdfConverter.PdfDocumentOptions.Height = float.Parse(contentHeightTextBox.Text);
// Set HTML content top and bottom spacing or leave them not set to have no spacing for the HTML content
htmlToPdfConverter.PdfDocumentOptions.TopSpacing = float.Parse(topSpacingTextBox.Text);
htmlToPdfConverter.PdfDocumentOptions.BottomSpacing = float.Parse(bottomSpacingTextBox.Text);https://stackoverflow.com/questions/43661100
复制相似问题