WkHtmlToXSharp如何添加页眉和页脚?

时间:2011-09-29 10:38:18

标签: pdf header converter footer wkhtmltopdf

我正在使用WkHtmlToXSharp(QT webkit)库构建HTML到PDF转换器,并且想知道是否有人知道如何在文档中添加页眉和页脚?我在这里看到了一些关于这个库的问题,但是找不到有关页眉和页脚的任何内容。

在wkhtmltopdf手册(http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html)中有关于页眉和页脚的文档,但我找不到任何内容。 .NET包装器库(WkHtmlToXSharp),它可能没有实现?

感谢您提供任何帮助或建议!

1 个答案:

答案 0 :(得分:0)

以下是我如何做的一些片段:

public class HeaderFooterSettings
{
    public string HtmlUrl { get; set; }
    public string Right { get; set; }
    public string Spacing { get; set; }
}

public class PdfObjectSettings
{
    private WebSettings _webSettings = new WebSettings();
    private LoadSettings _loadSettings = new LoadSettings();
    private HeaderFooterSettings _headerSettings = new HeaderFooterSettings();
    private HeaderFooterSettings _footerSettings = new HeaderFooterSettings();

    public string Page { get; set; }
    public string Cover { get; set; }
    public bool ProduceForms { get; set; }
    public bool PagesCount { get; set; }


    public HeaderFooterSettings Header { get { return _headerSettings; } }
    public HeaderFooterSettings Footer { get { return _footerSettings; } }
    public WebSettings Web { get { return _webSettings; } }
    public LoadSettings Load { get { return _loadSettings; } }


    // TODO: Add remaining settings..
    //see the following page for settings format http://www.cs.au.dk/~jakobt/libwkhtmltox_0.10.0_doc/pagesettings.html
}

以下是设置页眉和页脚网址的主要逻辑:

var objectSettings = new PdfObjectSettings();
objectSettings.Header.HtmlUrl = headerHtmlUrl;
objectSettings.Header.Spacing = ConfigurationManager.AppSettings["ContentSpacing"];
objectSettings.Footer.HtmlUrl = footerHtmlUrl;

我希望这会有所帮助。

拉​​菲