[Html2PdfConverter] HTML TO PDF - Generate PDF

[Html2PdfConverter] HTML TO PDF - Generate PDF

  
Forge Component
(51)
Published on 26 Sep (3 weeks ago) by Guilherme Pereira
51 votes
Published on 26 Sep (3 weeks ago) by Guilherme Pereira

Hello, i facing problems to generate a pdf from the html of the page!

Found some posts but didnt get...

My questions are:

How to configure the html2pdf so i will be able to generate pdfs?

What should i put on the URL and Proxy?

Can someone give a direct answer?

Im working on a project here on my company, waiting!

Thanks!

Hello Vinicius,


You configure your HTML2PDF using its application: 

In the administration screen you can upload the executables/libraries (you find those here: http://wkhtmltopdf.org/)

URL is the URL of the page (HTML) you want to convert to PDF.
Proxy you put "" unless you are under a proxy, than you put the proxy configuration.

Cheers,
Eduardo Jauch


Eduardo Jauch wrote:

Hello Vinicius,


You configure your HTML2PDF using its application: 

In the administration screen you can upload the executables/libraries (you find those here: http://wkhtmltopdf.org/)

URL is the URL of the page (HTML) you want to convert to PDF.
Proxy you put "" unless you are under a proxy, than you put the proxy configuration.

Cheers,
Eduardo Jauch


How do i get the url of the page?


Hello Vinicius,

What exactly are you trying to do?
If you are trying to convert a page, and you know its name, to make your app flexible, you can use the GetEntryURL function, passing two arguments: The module (eSpace), as the first argument, and the name of the page (without the extension) as the second input parameter. You can also give parameters to the page using this function, if the page require input parameters. 

Because the executable that will convert the page to PDF needs an absolute URL, you can put the GetEntrURL inside an MakeAbsoluteURL function.

Both functions are part of the HTTPRequestHandler extension and are described here:

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/HTTPRequestHandler_API

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hello Vinicius,

What exactly are you trying to do?
If you are trying to convert a page, and you know its name, to make your app flexible, you can use the GetEntryURL function, passing two arguments: The module (eSpace), as the first argument, and the name of the page (without the extension) as the second input parameter. You can also give parameters to the page using this function, if the page require input parameters. 

Because the executable that will convert the page to PDF needs an absolute URL, you can put the GetEntrURL inside an MakeAbsoluteURL function.

Both functions are part of the HTTPRequestHandler extension and are described here:

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/HTTPRequestHandler_API

Cheers,
Eduardo Jauch

Hello having some problems:

1: Configured on the htmltopdf website;

2: Putted on the url field:

MakeAbsoluteURL(GetEntryURL(GetPageName(),eSpaceName:GetEntryEspaceName(),FirstParameterName:,FirstParameterValue:,SecondParameterName:,SecondParameterValue:,ThirdParameterName:,ThirdParameterValue:,FourthParameterName:,FourthParameterValue:,FifthParameterName:,FifthParameterValue:))

And in proxy: ""

3: Receiving the error:

Could not find file 'C:\Users\CCCE64~1\AppData\Local\Temp\TEMPUVKCYIRQNE00000000000000000000000000000000.pdf'.

4: As you asked, i have a detail page and i wanna generate a pdf and download it from this detail page... Using the htmltopdf...

Cheers!

Hello Vinicius,

This is a very common error.

It means that the PDF that should be generated wasn't.
There are N reasons for that, but let's see if we can eliminate the simpler ones first.

1. Verify if the web page you are trying to convert to PDF has the anonymous Role checked. This is mandatory, as the executable that will load it will do this in an anonymous way. There are some ways to deal with this "security" question, if required.

2. Verify if you uploaded the correct binaries. The best option is to download the MingW option, as you will need only the executables (one for PDF, one for Image, and a single dll), at this link. The other version requires more files to be uploaded.

3. If you are using an On Premises server installation (your own server, not one provided by OutSystems in the cloud), check if the IIS has access to the Temp directory. If you are using a Cloud server, you are probably good here.

Usually, 95% of time, is a problem of access to the web page (1) or incorrect binaries (2).

Hope this helps solve this issue :)

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hello Vinicius,

This is a very common error.

It means that the PDF that should be generated wasn't.
There are N reasons for that, but let's see if we can eliminate the simpler ones first.

1. Verify if the web page you are trying to convert to PDF has the anonymous Role checked. This is mandatory, as the executable that will load it will do this in an anonymous way. There are some ways to deal with this "security" question, if required.

2. Verify if you uploaded the correct binaries. The best option is to download the MingW option, as you will need only the executables (one for PDF, one for Image, and a single dll), at this link. The other version requires more files to be uploaded.

3. If you are using an On Premises server installation (your own server, not one provided by OutSystems in the cloud), check if the IIS has access to the Temp directory. If you are using a Cloud server, you are probably good here.

Usually, 95% of time, is a problem of access to the web page (1) or incorrect binaries (2).

Hope this helps solve this issue :)

Cheers,
Eduardo Jauch

Hello, stil facing this erros:

Could not find file 'C:\Users\CCCE64~1\AppData\Local\Temp\TEMPXNOGHGTOBI00000000000000000000000000000000.pdf'.

I marked anonymous on the page, i downloaded the mingw and added the files!

What else could be? Can be this mingw files? 

Cheers!


Hi,

Your server is in an OutSystems cloud or you have your own server?

Can you provide a small OML so I can test on my installation to figure if it is a problem with the files?
A simple page, anonymous, with the action to convert to PDF and download it, the way you are doing will do. 

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hi,

Your server is in an OutSystems cloud or you have your own server?

Can you provide a small OML so I can test on my installation to figure if it is a problem with the files?
A simple page, anonymous, with the action to convert to PDF and download it, the way you are doing will do. 

Cheers,
Eduardo Jauch


Its an outsystems cloud...

Its on atachment!!


Eduardo Jauch wrote:

Hi,

Your server is in an OutSystems cloud or you have your own server?

Can you provide a small OML so I can test on my installation to figure if it is a problem with the files?
A simple page, anonymous, with the action to convert to PDF and download it, the way you are doing will do. 

Cheers,
Eduardo Jauch

I think the attachment didnt worked so sending pictures for you....


Hello Vinicius, 

I was talking about the module itself :)
But no problem.

Let's do a different test.

Do you set up the files like this, right?

From the MINGW, right? (the executables have around 28MB size)

Than, you go to this address: <put here your server address>//HtmlToPDFConverter/HowToPDF.aspx
And click the button "Google". It should give you a PDF of the main page of the google. 

If you get this correct and you receive a proper PDF, you have a problem in your APP (and I would like to take a look on it to be able to help you, even if everything seems ok)

If not, you can enable the LOG messages under the Administration page

And try the test again. Than go to the monitoring page (Service Center) and look for messages of this module/application so we can see what is the problem (with stack trace and everything).

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hello Vinicius, 

I was talking about the module itself :)
But no problem.

Let's do a different test.

Do you set up the files like this, right?

From the MINGW, right? (the executables have around 28MB size)

Than, you go to this address: <put here your server address>//HtmlToPDFConverter/HowToPDF.aspx
And click the button "Google". It should give you a PDF of the main page of the google. 

If you get this correct and you receive a proper PDF, you have a problem in your APP (and I would like to take a look on it to be able to help you, even if everything seems ok)

If not, you can enable the LOG messages under the Administration page

And try the test again. Than go to the monitoring page (Service Center) and look for messages of this module/application so we can see what is the problem (with stack trace and everything).

Cheers,
Eduardo Jauch

Hi, i made this test with google, he download a pdf and when i open this pdf he says this:

Error

Failed to load PDF document.

The problem are the files?



Eduardo Jauch wrote:

Hello Vinicius, 

I was talking about the module itself :)
But no problem.

Let's do a different test.

Do you set up the files like this, right?

From the MINGW, right? (the executables have around 28MB size)

Than, you go to this address: <put here your server address>//HtmlToPDFConverter/HowToPDF.aspx
And click the button "Google". It should give you a PDF of the main page of the google. 

If you get this correct and you receive a proper PDF, you have a problem in your APP (and I would like to take a look on it to be able to help you, even if everything seems ok)

If not, you can enable the LOG messages under the Administration page

And try the test again. Than go to the monitoring page (Service Center) and look for messages of this module/application so we can see what is the problem (with stack trace and everything).

Cheers,
Eduardo Jauch

On the log he returned me this:

2017-08-25 12:44:26HtmlToPdfConverter
(Html2PdfConverter)
Path [C:\OutSystems\Sandboxes\CCJL5R044\Platform Server\running\HtmlToPdfConverter\\binaries\wkhtmltopdf.exe] URL [www.google.com] Proxy [] OtherArgs [ ]DEBUG

Eduardo Jauch wrote:

Hello Vinicius, 

I was talking about the module itself :)
But no problem.

Let's do a different test.

Do you set up the files like this, right?

From the MINGW, right? (the executables have around 28MB size)

Than, you go to this address: <put here your server address>//HtmlToPDFConverter/HowToPDF.aspx
And click the button "Google". It should give you a PDF of the main page of the google. 

If you get this correct and you receive a proper PDF, you have a problem in your APP (and I would like to take a look on it to be able to help you, even if everything seems ok)

If not, you can enable the LOG messages under the Administration page

And try the test again. Than go to the monitoring page (Service Center) and look for messages of this module/application so we can see what is the problem (with stack trace and everything).

Cheers,
Eduardo Jauch

And when i try to do on the app:

Could not find file 'C:\Users\CCCE64~1\AppData\Local\Temp\TEMPQSNPJKVEUV00000000000000000000000000000000.pdf'.


Hi Vinicius,

Your application is ok. I can generate PDFs here without problems.

It's funny, because in our server, we had to use one pack (MSCV), but in my personal, I just installed and had to use the MING, as it didn't worked with the MSCV (probably missing some libraries)

Try this executables+library. If they don't work, you can try the version from the MSCV (here), but the first files are the ones I'm using in my personal (cloud), while the second link is the same as we have in local server. The first doesn't work in our local, the last doesn't work in my personal (cloud).

If none of the file sets works, you will need to talk to OutSystems (it seems to be an enterprise installation), to figure out what is the problem. If it is a personal, the first set will work. 

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hi Vinicius,

Your application is ok. I can generate PDFs here without problems.

It's funny, because in our server, we had to use one pack (MSCV), but in my personal, I just installed and had to use the MING, as it didn't worked with the MSCV (probably missing some libraries)

Try this executables+library. If they don't work, you can try the version from the MSCV (here), but the first files are the ones I'm using in my personal (cloud), while the second link is the same as we have in local server. The first doesn't work in our local, the last doesn't work in my personal (cloud).

If none of the file sets works, you will need to talk to OutSystems (it seems to be an enterprise installation), to figure out what is the problem. If it is a personal, the first set will work. 

Cheers,
Eduardo Jauch

Discovered the problem, the internet from my company was blocking or doing something that why wasnt working, i used the 4g from my phone and worked but on the pdf im receiving this error:

[CCJL5R044].DBO.[OSSYS_USER_T20] with key 0 was not found

An internal error occurred and was logged.Please try again later or contact the administration team.Sorry for any inconvenience

Probably the url isnt right...


Vinicius Schonardie wrote:

Eduardo Jauch wrote:

Hi Vinicius,

Your application is ok. I can generate PDFs here without problems.

It's funny, because in our server, we had to use one pack (MSCV), but in my personal, I just installed and had to use the MING, as it didn't worked with the MSCV (probably missing some libraries)

Try this executables+library. If they don't work, you can try the version from the MSCV (here), but the first files are the ones I'm using in my personal (cloud), while the second link is the same as we have in local server. The first doesn't work in our local, the last doesn't work in my personal (cloud).

If none of the file sets works, you will need to talk to OutSystems (it seems to be an enterprise installation), to figure out what is the problem. If it is a personal, the first set will work. 

Cheers,
Eduardo Jauch

Discovered the problem, the internet from my company was blocking or doing something that why wasnt working, i used the 4g from my phone and worked but on the pdf im receiving this error:

[CCJL5R044].DBO.[OSSYS_USER_T20] with key 0 was not found

An internal error occurred and was logged.Please try again later or contact the administration team.Sorry for any inconvenience

Probably the url isnt right...


Hi Vinicius,

Nope. The error you are experiencing is that you are trying to convert to PDF a page that requires a UserId, probably from the Logged UserId, or from an Input Parameter.

But as this page will be called by the executable, that does not know anything about the page itself, you will have to pass the UserId using the parameters in the GetEntryURL, so that this will be passed to the page when it is called by the PDF executable.

Yeah. I found it.
On my test, I deleted everything just to test the PDF and the PDF was working.

But the aggregate in your page requires the logged user id:

So, I suggest you to add UserId as input parameter to the page and use it in the filter, instead of the GetUserId().
In fact, you should never use this form GetTable(id), because if the Id is NullIdentifier, you will get an error.

So, change your filter to something like this: Ctsc.Ctc = UserName 

In the preparation, you fill the UserName with GetUser(UserId).user.UserName, where this UserId is the input parameter, and you use the GetUserId() in the links to this page.

Then add the UserId to the page address of the page in the form:

MakeAbsoluteURL(GetEntryURL(GetPageName(),GetEntryEspaceName(),"UserId",GetUserId()))

And it will work (I hope) ;)

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Yeah. I found it.
On my test, I deleted everything just to test the PDF and the PDF was working.

But the aggregate in your page requires the logged user id:

So, I suggest you to add UserId as input parameter to the page and use it in the filter, instead of the GetUserId().
In fact, you should never use this form GetTable(id), because if the Id is NullIdentifier, you will get an error.

So, change your filter to something like this: Ctsc.Ctc = UserName 

In the preparation, you fill the UserName with GetUser(UserId).user.UserName, where this UserId is the input parameter, and you use the GetUserId() in the links to this page.

Then add the UserId to the page address of the page in the form:

MakeAbsoluteURL(GetEntryURL(GetPageName(),GetEntryEspaceName(),"UserId",GetUserId()))

And it will work (I hope) ;)

Cheers,
Eduardo Jauch

Putted the user on the url and worked!

Thanks a lot djow!


Eduardo Jauch wrote:

Yeah. I found it.
On my test, I deleted everything just to test the PDF and the PDF was working.

But the aggregate in your page requires the logged user id:

So, I suggest you to add UserId as input parameter to the page and use it in the filter, instead of the GetUserId().
In fact, you should never use this form GetTable(id), because if the Id is NullIdentifier, you will get an error.

So, change your filter to something like this: Ctsc.Ctc = UserName 

In the preparation, you fill the UserName with GetUser(UserId).user.UserName, where this UserId is the input parameter, and you use the GetUserId() in the links to this page.

Then add the UserId to the page address of the page in the form:

MakeAbsoluteURL(GetEntryURL(GetPageName(),GetEntryEspaceName(),"UserId",GetUserId()))

And it will work (I hope) ;)

Cheers,
Eduardo Jauch

HeyEduardo how are you? Im facing something about this, sometimes i will have a list of Products lets say, and i want to show this on the pdf in a pretty way... I wanted to use the table records, but this doesnt work, like work but doesnt show everything or a pretty way, i need to format something to show properly? How it works?

Thanks!


Hello Vinicius,

In theory, what the pdf conversor does is to create a PDF version of the web page, exactly as it is.
Can you share a picture of your page and a PDF to us to see about what's the problem?

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hello Vinicius,

In theory, what the pdf conversor does is to create a PDF version of the web page, exactly as it is.
Can you share a picture of your page and a PDF to us to see about what's the problem?

Cheers,
Eduardo Jauch

This is how i want to appear, will show more than one...

This is how he puts on the pdf:

He shows only one column and full fill the hole space...

Hum... The server is assuming that your page should be displayed in mobile...
This is the reason why it is "changing" the style.

Are you asking the PDF from a "mobile"? This is a silly question, as the executable asking the page is in the server... Anyway...

Hum...

Let me ask something less stupid...
Are you setting any parameter in the Action that executes the conversion to limit the size of the page?

If this is the case (and you need this way), you can define this style in the Style of the TableRecords: "TableRecords NoResponsive"

This will prevent the table of change if the server thinks the page is too small.

Cheers,
Eduardo Jauch

Hi Vinicius,


The output you're getting is perfectly normal. As the output page is A4 size by default in terms of size vs resolution it is interpreted as being displayed on tablet hence the output.


As Eduardo suggested you could add the NoResponsive style to your table to prevent it from breaking up other responsive behaviors could be applied. If you want to avoid all responsive behaviors (as well as known SILK UI incompatibility) what you can do is create a complete new blank theme not inheriting from any other and then apply it to a new webflow with the page to be printed. For this you to have two versions of the page (one for showing and one for printing to pdf) but should eliminate any responsive behavior.


Cheers,

Guilherme

I changed to Table records no responsive, i just copied this there, dont even had the option but he accepted, but didnt worked...

Guilherme Pereira wrote:

Hi Vinicius,


The output you're getting is perfectly normal. As the output page is A4 size by default in terms of size vs resolution it is interpreted as being displayed on tablet hence the output.


As Eduardo suggested you could add the NoResponsive style to your table to prevent it from breaking up other responsive behaviors could be applied. If you want to avoid all responsive behaviors (as well as known SILK UI incompatibility) what you can do is create a complete new blank theme not inheriting from any other and then apply it to a new webflow with the page to be printed. For this you to have two versions of the page (one for showing and one for printing to pdf) but should eliminate any responsive behavior.


Cheers,

Guilherme

How i put this different theme just for a page?


Hello Vinicius,

The "NoResponsive" should have done the trick. Can you share to take a look?

In any case, you can define a different theme in an application in a different flow. (Each flow can use a different theme).

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

Hello Vinicius,

The "NoResponsive" should have done the trick. Can you share to take a look?

In any case, you can define a different theme in an application in a different flow. (Each flow can use a different theme).

Cheers,
Eduardo Jauch

If the no responsive doesnt work, i will ask you for a better explanation about the theme... hah

This is how im doing.... Just copied the phrase: TableRecord NoResponsive, as its there, and didnt worked!

Eduardo Jauch wrote:

Hello Vinicius,

The "NoResponsive" should have done the trick. Can you share to take a look?

In any case, you can define a different theme in an application in a different flow. (Each flow can use a different theme).

Cheers,
Eduardo Jauch

Hello Eduardo, any idea?


Hello Vinicius,

Are you using a Silk UI theme? It works only in Silk UI...
I have to do some tests, but will have time only tomorrow.

Cheers,
Eduardo Jauch

Solution

Eduardo Jauch wrote:

Hello Vinicius,

Are you using a Silk UI theme? It works only in Silk UI...
I have to do some tests, but will have time only tomorrow.

Cheers,
Eduardo Jauch


I did it, i changed the theme off the page and putted no responsive and workedd!!

Solution

Hello Vinicius!

I'm glad we were able to help you find the solution :)

I'll ask a small favor.
Regarding the correct answer, please, mark one of the answers related to the original question, as this will help people one searching the forum. ;)

Thanks!

Cheers,
Eduardo Jauch

Hi Eduardo,

I really appreciate your patience and help on this topic, i am too facing some issues regarding this component but now i am all clear.

Regards,

Manish Jawla

Good to hear, Manish :)

Appreciate the help just finished it and working great.
http://html-2-pdf.com