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

Converter.convert works exactly twice #12

Closed corymickelson closed 6 years ago

corymickelson commented 6 years ago

I have an api, that just passes an html string, which is then passed to this


        static public byte[] HtmlToPdf(string html)
        {
            var converter = new BasicConverter(new PdfTools());
            var doc = new HtmlToPdfDocument()
            {
                GlobalSettings = {
                    ColorMode = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize = PaperKind.A4Plus
                }, 
                Objects = {
                    new ObjectSettings()
                    {
                        PagesCount = true,
                        HtmlContent = html,
                        WebSettings = {DefaultEncoding = "utf-8"}
                    }
                }
            };
            return converter.Convert(doc); // <--- hangs here on 3rd time called
        }

This call only works twice though?? After the second time this method has been invoked it will just hangs on the converter.Convert() call. Any idea's? Thanks.

rdvojmoc commented 6 years ago

You must declare it as singleton. That way native library is loaded you once.

corymickelson commented 6 years ago

@rdvojmoc Thank you