How to set PageOptions in TuesPechkin

2.4k views Asked by At

I'm using TuesPechkin (the C# wrapper of wkhtmltopdf) and have it generating PDF files from HTML.

However, I would like to set the --disable-smart-shrinking option, which is listed in the wkhtmltopdf documentation as a PageOption

How can I do that?

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);
    }
}
2

There are 2 answers

0
tuespetre On BEST ANSWER

The --disable-smart-shrinking option does not exist in the API -- well, it kind of does, but in the form of it's opposite sibling: --enable-smart-shrinking.

That property is available in the TuesPechkin API as 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.

You can also see there that the default value is true (from wkhtmltopdf), so if you set WebSettings.EnableIntelligentShrinking to false you should get the result you're aiming for.

0
Nic On

It seems this functionality hasn't been implemented in Tuespechkin. I can't find it here, where most of the page options are located.

I guess he forgot to implement the option, so probably best to request the feature here. Or you can also add the feature yourself. :)