[Html2PdfConverter] Can't use wkhtmltopdf parameters

[Html2PdfConverter] Can't use wkhtmltopdf parameters

  
Forge Component
(52)
Published on 30 Oct by Guilherme Pereira
52 votes
Published on 30 Oct by Guilherme Pereira

Hi.

I was using HtmlToPDFConverter but when I neeeded to use (for example) --footer-center [page]/[topage] I got the following response error on GeneratePDF action:

'The switch --footer-html, is not support using unpatched qt, and will be ignored.SetProcessDpiAwareness failed: "COM error 0x80070005  (Unknown error 0x0ffffffff80070005)"'

That component seems to be based on a non release (bleeding edge) version of wkhtmltopdf, which doesn't have all the features of the executable.

If I upload the most recent version of the wkhtmltopdf, I get a blank page with no response from the GeneratePDF action.

Hi Rodrigo,


The component is not based in any specific version. It depends on the executables and dlls that the users upload.


If you upload the bleeding edge (personally that's the one I recommend as it covers 99% of the uses cases) then not all features may be available. If you upload a different version then you need to make sure that all the dependencies are also installed in the server.


I'd recommend login into the server and execute wkhtmltopdf from the command line t see if it runs. 


Cheers,

Guilherme

I've tried few of the most recent versions of wkhtmltopdf, from 12.3.x to 12.5.x and all of them (always setting the dependencies correctly according to the package I downloaded) gives me a blank page of PDF. The only version that prints my HTML to PDF is the latest bleeding edge version, which desn't gives me the options for "--footer-x or --header-x".

Have you tried from the command line? Does it work with the newer versions with that approach?

Guilherme Pereira wrote:

Have you tried from the command line? Does it work with the newer versions with that approach?

No, I can't try, I don't have access to the server which app is runing...

I'm trying to use custom footer and header, but still no success. The only URL that works as custom header and footer is www.google.com, any other page I get a blank PDF page...


Edit.: The following OtherArgs I set, gives me a blank page with no response from Action:

SyntaxEditor Code Snippet

 " --footer-html " + EntryURLFooter

Guilherme Pereira wrote:

If you upload the bleeding edge (personally that's the one I recommend as it covers 99% of the uses cases) then not all features may be available. 

99% of the use cases? Really?

It doesn't accept arguments like -R 0 or -L 0... which I needed to try.

I think it's very limited in terms of command line arguments supported...

You can try from your lical pc via command line. If it’s just in your pages you must have something thee that may be causing it (e.g a javascript or css). 

You also need to validate that the server has access to the page with the url you’re using and also that the page is set to anonymous.

I suggest starting with a blank page and progressively add your elements until you find the cause.

Guilherme Pereira wrote:

You can try from your lical pc via command line. If it’s just in your pages you must have something thee that may be causing it (e.g a javascript or css). 

You also need to validate that the server has access to the page with the url you’re using and also that the page is set to anonymous.

I suggest starting with a blank page and progressively add your elements until you find the cause.

I have 2 local variables to achieve what I want.

1st is EntryURL - Which will contain my content URL.

2nd is EntryURLFooter - Which will contain the HTML for my footer.

I did a test, as you suggested, where I just put the EntryURLFooter to be printed where the EntryURL should be. Did this to check if wkhtmltopdf is fit to renderize my footer HTML.

It just did print as should be printed. No problems with accessing my foot HTML.

You said me to try to execute via command line. But www.google.com prints as footer, other URLs than that just doesn't.

João Heleno wrote:

Guilherme Pereira wrote:

If you upload the bleeding edge (personally that's the one I recommend as it covers 99% of the uses cases) then not all features may be available. 

99% of the use cases? Really?

It doesn't accept arguments like -R 0 or -L 0... which I needed to try.

I think it's very limited in terms of command line arguments supported...


Hi joão. 


For me personally the bleeding edge version works pretty well but if you can try other versions that work better for you great. That’s why the component allows you to upload your binaries so you can use the ones that are best suited for you.


Cheers,

Guilherme

Rodrigo Leonardo Corrêa de Paula wrote:

Guilherme Pereira wrote:

You can try from your lical pc via command line. If it’s just in your pages you must have something thee that may be causing it (e.g a javascript or css). 

You also need to validate that the server has access to the page with the url you’re using and also that the page is set to anonymous.

I suggest starting with a blank page and progressively add your elements until you find the cause.

I have 2 local variables to achieve what I want.

1st is EntryURL - Which will contain my content URL.

2nd is EntryURLFooter - Which will contain the HTML for my footer.

I did a test, as you suggested, where I just put the EntryURLFooter to be printed where the EntryURL should be. Did this to check if wkhtmltopdf is fit to renderize my footer HTML.

It just did print as should be printed. No problems with accessing my foot HTML.

You said me to try to execute via command line. But www.google.com prints as footer, other URLs than that just doesn't.

Hi Rodrigo,


My suggestion to try the command line is so that you can find the version that works for you first and then upload that to the server.

The component allows you to pretty much use any version but for example the MSVC version requires MSVC to be installed on the server and if you can do it that may be a deal breaker fir you.

My personal experience with wkhtmltopdf and htm2pdf tells me that If you download it to your pc and try with different urls you may more easily find a version that works for you instead of uploading it to the server only to find out that it doesn’t work for you.


Cheers,

Guilherme


Solution

I did try with command line and found a workaround.


The args weren't working on some URIs that I was sending to the wkhtmltopdf (I made 2 internal routes to print my header and footer).


Then I realize that everything was ok with my header and footer routes when I did some tests with random URLs (http and https). Just few was working (like google.com or facebook.com), all the rest weren't printing.


So I thought that could be the <!DOCTYPE HTML> on the beginnig these contents from the non-working URLs and just did my header.html and footer.html to the root of the wkhtmltopdf and tried to load from there. It worked like a charm.


All I had to do was to open my WebBlocks HTML, concat the <!DOCTYPE HTML>, save them into a temp folder, and send to wkhtmltopdf the temp path.


I could avoid all these extra works if the tool just worked correct with the --header-html and --footer-html.


PS.: I'm working with wkhtmltopdf on the 12.5.1 version. The bleeding edge is just incomplete and shouldn't be recommended :/


Solution

Hi Rodrigo,


I’m glad you found a solution. The bleeding edge is recommended not because is better ( and apparently for you is not ) but because many of OutSystems customers are now in the cloud where they can’t install versions that have dependencies that need to be installed on the machine (as that isn’t possible).


But based on your feedback I’ll review the FAQ to make this clear.


Cheers,

Guilherme

Rodrigo Leonardo Corrêa de Paula wrote:

I did try with command line and found a workaround.


The args weren't working on some URIs that I was sending to the wkhtmltopdf (I made 2 internal routes to print my header and footer).


Then I realize that everything was ok with my header and footer routes when I did some tests with random URLs (http and https). Just few was working (like google.com or facebook.com), all the rest weren't printing.


So I thought that could be the <!DOCTYPE HTML> on the beginnig these contents from the non-working URLs and just did my header.html and footer.html to the root of the wkhtmltopdf and tried to load from there. It worked like a charm.


All I had to do was to open my WebBlocks HTML, concat the <!DOCTYPE HTML>, save them into a temp folder, and send to wkhtmltopdf the temp path.


I could avoid all these extra works if the tool just worked correct with the --header-html and --footer-html.


PS.: I'm working with wkhtmltopdf on the 12.5.1 version. The bleeding edge is just incomplete and shouldn't be recommended :/


Hi Rodrigo,

Can you please elaborate a little more regarding the section below?

"So I thought that could be the <!DOCTYPE HTML> on the beginnig these contents from the non-working URLs and just did my header.html and footer.html to the root of the wkhtmltopdf and tried to load from there. It worked like a charm.

All I had to do was to open my WebBlocks HTML, concat the <!DOCTYPE HTML>, save them into a temp folder, and send to wkhtmltopdf the temp path."

Thanks