codaxy / wkhtmltopdf

C# wrapper around excellent wkhtmltopdf console utility.
265 stars 92 forks source link

ContentNotFoundError caused by missing page elements like 404 js. #22

Closed qiansen1386 closed 7 years ago

qiansen1386 commented 7 years ago

Because there is a failed js request, then even the wkhtmltopdf returns Done, our lib is still returning ContentNotFoundError

Result Message: 
Test method Util.PDF.Test.TestPDF.TestHTML_Codaxy_NoRadius threw exception: 
Util.PDF.Codaxy.WkHtmlToPdf.PdfConvertException: Html to PDF conversion of document failed. Wkhtmltopdf output: 
Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[==========>                                                 ] 18%
Warning: Failed to load file://inpref-asia.s3.amazonaws.com/sites/misatravel_com.js (ignore)
[==========>                                                 ] 18%
[===============>                                            ] 26%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
Printing pages (6/6)
[>                                                           ] Preparing
[============================================================] Page 1 of 1
Done                                                                      
Exit with code 1 due to network error: ContentNotFoundError

I am using @fean 's fork AuthiQ/wkhtmltopdf Because #13

Currently I am resolving this by adding a try catch around, however I am not sure if there is any side-effect

Try
    PdfConvert.ConvertHtmlToPdf(New PdfDocument() With {.Html = html},
                            New PdfOutput() With {.OutputFilePath = path})
Catch ex As Exception When ex.Message.Contains("ContentNotFoundError")
    'Ignore ContentNotFoundError due to 404 elements
End Try
qiansen1386 commented 7 years ago

BTW, the file is actually generated perfectly.

mstijak commented 7 years ago

This is very strange because there is a check which ignores any errors if the file was created successfully. Did you try to debug?

qiansen1386 commented 7 years ago

@mstijak Let me check. Maybe the check is missing from AuthiQ branch.

mstijak commented 7 years ago

I just published a new version on NuGet. You may try it.

qiansen1386 commented 7 years ago

Yeah, I am also checking the code 😆 Thanks.

qiansen1386 commented 7 years ago

@mstijak Your new patch works great, much more elegant than fean's or my patch. 🙌🙌🙌 Thanks a lot