HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
366 stars 66 forks source link

Weird errors that I can't pin point #95

Closed JustasKvederis closed 1 year ago

JustasKvederis commented 1 year ago

Hello, thanks for your last response (it was very helpful). This time I am having a different issue. I am writing a simple console application that generates PDF's.... And it works, but it still throws these two errors: Qt: Could not initialize OLE (error 80010106) QWaitCondition: Destroyed while threads are still waiting

One is thrown at the beginning of the execution only once (no matter how many times I generate files), after this line: byte[] pdft = pdfConverter.Convert(doct);

and the one at the end of the execution.

For the second Error I tried to add Thread.sleep, to see if I keep the console alive for longer it might help, but it did not. Do you have any insights into it ?

HakanL commented 1 year ago

There is a console example in the repo, have you tried that?

JustasKvederis commented 1 year ago

I just had a look, but it seems identical in the most important areas. I create a Basicconverter with pdf tools, then I create the document with the settings, which are similar and I try to convert and i get that error as I mentioned it still works it creates the pdf, but I was wondering how to fix the errors/warnings, but if they are harmless I guess I can just ignore them.

JustasKvederis commented 1 year ago

pdfConverter = new(new PdfTools());

` var doc = htmlDoc.DocumentNode.InnerHtml;

        var doct = new HtmlToPdfDocument()
        {
            GlobalSettings = {
                ColorMode = ColorMode.Color,
                Orientation = Orientation.Landscape,
                PaperSize = PaperKind.A4,
                Margins = new MarginSettings(){ Left = 15, Bottom = 23, Right = 5, Top = 20, Unit = Unit.Millimeters },
                DPI = 200,
            },
            Objects = {
                new ObjectSettings() {
                    HtmlContent = htmlDoc.DocumentNode.InnerHtml,
                    WebSettings = { DefaultEncoding = "utf-8" },
                    HeaderSettings = {Spacing = -5,HtmlUrl = "Header.html"},
                    FooterSettings = {Spacing = 2, HtmlUrl = "Footer.html"}
                }
            }
        };
        byte[] pdft = pdfConverter.Convert(doct);`
HakanL commented 1 year ago

You will get some warnings, which is normal, but you mentioned that errors were thrown. As long as the document is generated then you should be good.

erickvalderrama commented 1 year ago

I just had a look, but it seems identical in the most important areas. I create a Basicconverter with pdf tools, then I create the document with the settings, which are similar and I try to convert and i get that error as I mentioned it still works it creates the pdf, but I was wondering how to fix the errors/warnings, but if they are harmless I guess I can just ignore them.

I hope this help you:

First:

image

Then:

image

So...:

image

HakanL commented 1 year ago

Is it an exception, or a warning? If it's an exception, what is the exception?

erickvalderrama commented 1 year ago

No, it is not a exception. Just it is freezing app when we creating instances of IConvert inside functions or methods, so it just allow call IConvert once.

HakanL commented 1 year ago

Do you mean it's hanging when you call .Convert, or when you create an instance of SynchronizedConverter? This doesn't sound like it's related to this issue, that was opened due to the warnings the library outputs.

JustasKvederis commented 1 year ago

Is it an exception, or a warning? If it's an exception, what is the exception?

Sorry for the late reply, yes it's just a warning, it works if you ignore the warnings.

JustasKvederis commented 1 year ago

No, it is not a exception. Just it is freezing app when we creating instances of IConvert inside functions or methods, so it just allow call IConvert once.

Sorry it does not freeze and it does work just with the exceptions. But since it's a console application it doesn't really have DI, I can't add it to the builder. There are work arounds, but I doubt that it's the issue.

HakanL commented 1 year ago

Ok, yes, you need to ignore the warnings, because they are just warnings about the environment (and they are coming from the native library, so not something we can affect in this wrapper project.

Ok, it's a little confusing when you say exceptions. Exceptions stop execution and prevent the function to work. Warnings (that are just outputted to logs) are not exceptions. So if I understand you there are no exceptions, everything works, nothing freezes? There are examples in this repo on how to call this from console without using DI.

JustasKvederis commented 1 year ago

Ok, yes, you need to ignore the warnings, because they are just warnings about the environment (and they are coming from the native library, so not something we can affect in this wrapper project.

Ok, it's a little confusing when you say exceptions. Exceptions stop execution and prevent the function to work. Warnings (that are just outputted to logs) are not exceptions. So if I understand you there are no exceptions, everything works, nothing freezes? There are examples in this repo on how to call this from console without using DI.

Yeah there are no exceptions, sorry for the incorrect terminology. Yes everything works and I saw the example I was just answering erick, because he suggested DI. Thanks, for your responses all is well.