Closed sumankr1 closed 3 years ago
Hi. I think is not an issue in my Go library and this will also happen when you call wkhtmltopdf directly.
But to give you some more context, I think this error is actually correct and your script cannot access a resource you you are trying to load.
This can have multiple reeasons, so I would suggestion adding some logging in your loop to see which of your XMLHttpRequests actuallly goes wrong. That is hard to see because you are looping over all files there.
Make sure that all files in your HTML document, including javascript and CSS resources have to point to the full path, so use https://<domain>/script.js
and not /script.js
. But in your case it might just be that your trying to load a file which simply does not exist.
If all else fails you can try to ignore the error by setting page.LoadErrorHandling("ignore")
and the ncheck which resource is actually missing in your PDF.
https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/master/options.go#L81
There are a lot more hints at https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2051but ultimately this seems to be a valid error and not a bug.
Thanks! There was a problem from my side.
Just a note for anyone in the future, you might be able to ignore this error and the pdf still be generated correctly.
I was able to get the bytes even though this error was cropping up for me. In my use-case, I don't particularly care if specific content can't load and LoadErrorHandling("ignore")
wasn't working for me. I was able to check the content of the error and ignore it.
err := pdfg.Create()
if !strings.Contains(fmt.Sprint(err), "ContentNotFoundError") {
return err
}
I'm trying to run some javascript code inside the
script
tag. Here is the console error output.As soon as I remove JS from the HTML file, the PDF is generated properly.
Here is the JS snippet: