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

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

感谢您的帮助或建议!

最佳答案

以下是一些有关我的操作方法的摘要:

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
}


这是设置页眉和页脚URL的主要逻辑:

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


我希望这有帮助。

拉菲

关于pdf - WkHtmlToXSharp如何添加页眉和页脚?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7596069/

10-15 13:48