How to convert HTML to PDF

Hi,


I want to convert html to pdf in java, but I can’t get any satisfactory solution from anywhere, can any body give me how to use Aspose.pdf or any demo which convert html to pdf.

note: please give solution for java.

Thanks,
Sandeep

Hi Sandeep,


Thanks for your inquiry. You may convert HTML to PDF using Aspose.Pdf for Java. Please check following documentation link for the purpose. Hopefully it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal Ahmad,


Thanks for your reply, I tried using solution which you have given me. Using that, pdf file is created but its blank,

Following is the HTML code which I am trying to convert into pdf,

Name Id Address
Kashif 007 US
Arshil 006 US
San 005 UK

Thanks,
Sandeep

Hi Sandeep,

Thanks for sharing the details.

I have tested the scenario using latest release of Aspose.Pdf for Java 9.3.1 and as per my observations, the resultant PDF is properly being generated. Please ensure that you are using a valid license to test the scenario. In case you do not have a license, you may consider requesting a 30 days temporary license to test the API without any limitations. For more information, please visit Get a temporary license

For your reference, I have also attached the resultant PDF generated over my end.

[Java]

//Specify
the The base path/url for the html file which serves as images database<o:p></o:p>

String basePath = “C:/pdftest/”;

com.aspose.pdf.HtmlLoadOptions htmloptions = new com.aspose.pdf.HtmlLoadOptions(basePath);

//use the new conversion engine

htmloptions.setUseNewConversionEngine(true);

//load HTML file

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(basePath + “html+page.html”, htmloptions);

//Save HTML file

doc.save(“c:/pdftest/Web+_output.pdf”);