rdvojmoc / DinkToPdf

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
MIT License
1.08k stars 415 forks source link

Process quits #40

Closed turowicz closed 4 years ago

turowicz commented 6 years ago

Hey, I have the following code:

                _converter = new SynchronizedConverter(new PdfTools());

                var doc = new HtmlToPdfDocument()
                {
                    GlobalSettings =
                    {
                        PaperSize = PaperKind.A4,
                        ColorMode = ColorMode.Color,
                        Orientation = Orientation.Portrait,
                    },
                    Objects =
                    {
                        new ObjectSettings()
                        {
                            PagesCount = false,
                            HtmlContent = html,
                            WebSettings = { DefaultEncoding = "utf-8" },
                            HeaderSettings = { },
                            FooterSettings = { },
                        }
                    }
                };

                return _converter.Convert(doc);

The program exits without any error or exit code on line:

return _converter.Convert(doc);

The input html is:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

Any ideas what may be wrong? The 3rd party library files are in bin via Target:

    <Target Name="CopyCustomContent" AfterTargets="AfterBuild">
        <Copy SourceFiles="..\..\lib\libwkhtmltox.so" DestinationFolder="$(OutDir)" />
        <Copy SourceFiles="..\..\lib\libwkhtmltox.dll" DestinationFolder="$(OutDir)" />
        <Copy SourceFiles="..\..\lib\libwkhtmltox.dylib" DestinationFolder="$(OutDir)" />
    </Target>

I'm running dotnet core 2.1 on OSX.

PS. Multithreading is a non-issue as this is a single unit test.

turowicz commented 6 years ago

Output before crash:

testhost Information: 0 : Phase changed 0 - Loading pages
testhost Information: 0 : Progress changed 0%
testhost Information: 0 : Progress changed 10%
testhost Information: 0 : Progress changed 50%
testhost Information: 0 : Progress changed 100%
testhost Information: 0 : Phase changed 1 - Counting pages
testhost Information: 0 : Progress changed Object 1 of 1
testhost Information: 0 : Phase changed 3 - Resolving links
testhost Information: 0 : Progress changed Object 1 of 1
testhost Information: 0 : Phase changed 4 - Loading headers and footers
testhost Information: 0 : Phase changed 5 - Printing pages
testhost Information: 0 : Progress changed Preparing
fabs-rodriguez commented 5 years ago

I think it could be related to "PagesCount = false". I get a "System.DivideByZeroException" when I set PagesCount to false. I see it was an issue that has been closed: https://github.com/rdvojmoc/DinkToPdf/issues/22