wooio / htmltopdf-java

An HTML to PDF conversion library written in Java, based on wkhtmltopdf.
MIT License
173 stars 97 forks source link

Saving a webpage from URL as a PDF file does not generate pdf #19

Closed mamunchy closed 5 years ago

mamunchy commented 5 years ago

I am using spring boot 2.0.5 and 2.1.1 Saving HTML as a PDF file is generating file boolean success = HtmlToPdf.create() .object(HtmlToPdfObject.forHtml("

Apples, not oranges

")) .convert("/path/to/file.pdf");

but "Saving a webpage from URL as a PDF file IS NOT WORKING

boolean success = HtmlToPdf.create() .object(HtmlToPdfObject.forUrl("https://github.com/wooio/htmltopdf-java")) .convert("/path/to/file.pdf"); EVEN NOT GIVE ANY ERROR.

benbarkay commented 5 years ago

Have you tried with a non-https URL? What do you get when you try to convert http://benbarkay.com/test.html ?

If this works, then it's likely that you are missing libssl1.0.

mamunchy commented 5 years ago

i have tried to convert http://benbarkay.com/test.html

but same, no pdf is generated, no error log i am using windows 10, java 1.8, spring boot 2.0.5 and 2.1.1

benbarkay commented 5 years ago

What's printed out if you add .error(System.out::println) before the call to .convert(...)? Can you write to that location normally? Say by running something like:

try (FileWriter fw = new FileWriter(PATH_TO_PDF, false)) {
  fw.append("test");
}

If it's not that, then can your process access http://benbarkay.com/test.html? Maybe the application is blocked by firewall or some other "security" software.

mamunchy commented 5 years ago

my system can access http://benbarkay.com/test.html, using .error(System.out::println) now get an error:

[500] Internal Server Error io/woo/htmltopdf/HtmlToPdf

benbarkay commented 5 years ago

From the above error message it appears that the remote server is failing to generate a response

dariosilva commented 5 years ago

I'm also unable to generate a pdf from a URL. With the following code:

File report = File.createTempFile("report", ".pdf");
HtmlToPdf.create() 
  .object(HtmlToPdfObject.forUrl("http://benbarkay.com/test.html"))
  .error(System.out::println)
  .convert(report.getAbsolutePath());

Generates the following output error:

Failed loading page http:// (sometimes it will work just to ignore this error with --load-error-handling ignore)

This happens for the version 1.0.6.

plumpNation commented 5 years ago

I too get the url load error.

Failed loading page http:// (sometimes it will work just to ignore this error with --load-error-handling ignore)

benbarkay commented 5 years ago

Sorry about that. Fixed in 1.0.7, should be public in central within several minutes.

dariosilva commented 5 years ago

Many thanks @benbarkay

Developer74 commented 1 year ago

@benbarkay can you please help me in adding page count in footer and customizable pagesize for my pdf

Here is my code boolean success = HtmlToPdf.create().pageSize(PdfPageSize.A4) .object(HtmlToPdfObject.forHtml(htmlString). headerFontSize(12). headerCenter("My Pdf title"). pageCount(true)) .convert(destination);