【问题标题】:How to set PageOptions in TuesPechkin如何在 TuesPechkin 中设置 PageOptions
【发布时间】:2015-08-28 12:06:44
【问题描述】:

我正在使用TuesPechkin(wkhtmltopdf 的 C# 包装器)并让它从 HTML 生成 PDF 文件。

但是,我想设置 --disable-smart-shrinking 选项,它在 wkhtmltopdf documentation 中作为 PageOption 列出

我该怎么做?

public sealed class PdfConverter
{
    static readonly PdfConverter instance = new PdfConverter();
    private IConverter converter;

    static PdfConverter()
    {
    }

    PdfConverter()
    {
        // Keep the converter somewhere static, or as a singleton instance! Do NOT run this code more than once in the application lifecycle!
        this.converter = new ThreadSafeConverter( new RemotingToolset<PdfToolset>( new Win32EmbeddedDeployment( new TempFolderDeployment())));
    }

    public static PdfConverter Instance
    {
        get { return instance; }
    }

    public byte[] ConvertHtmlToPdf(string html)
    {
        var document = new HtmlToPdfDocument
        {
            Objects = { new ObjectSettings { HtmlText = html } }

            // Where are PageOptions?  Thats where --disable-smart-shrinking is
        };

        return converter.Convert(document);
    }
}

【问题讨论】:

    标签: c# .net wkhtmltopdf tuespechkin


    【解决方案1】:

    --disable-smart-shrinking 选项在 API 中不存在——嗯,它有点存在,但以它的相反兄弟的形式:--enable-smart-shrinking

    该属性在 TuesPechkin API 中以 WebSettings.EnableIntelligentShrinking as seen in the TuesPechkin source code 的形式提供。它在 TuesPechkin 中是这样命名的,因为它在 wkhtmltopdf 的 API as seen in the wkhtmltopdf source code 中就是这样命名的。

    您还可以在此处看到默认值为 true(来自 wkhtmltopdf),因此如果您将 WebSettings.EnableIntelligentShrinking 设置为 false,您应该会得到您想要的结果。

    【讨论】:

      【解决方案2】:

      Tuespechkin 中似乎没有实现此功能。我找不到它here,大部分页面选项都位于。

      我猜他忘了实现这个选项,所以最好请求功能here。或者您也可以自己添加该功能。 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-10
        • 1970-01-01
        • 2015-07-25
        • 2015-07-07
        相关资源
        最近更新 更多