如何在 TuesPechkin 中设置 PageOptions

How to set PageOptions in TuesPechkin

我正在使用 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);
    }
}

Tuespechkin 似乎还没有实现这个功能。我找不到它 here,大多数页面选项所在的位置。

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

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

属性 在 TuesPechkin API 中可用 WebSettings.EnableIntelligentShrinking as seen in the TuesPechkin source code. It was named that way in TuesPechkin because that is how it is named in wkhtmltopdf's API as seen in the wkhtmltopdf source code

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