Convert HTML to PDF by java program

Hi,

We have requirement for converting HTML to PDF file based on HTML format in java program.

Currently we are using below jar files for aspose-pdf-2.7.0-jdk15.jar & aspose-pdf-kit-3.7.0.jar for other purpose in production environment.

I am attaching one sample HTML file. rename the TXT to html.

Please check and update me.

If you have any queries then inform me.

Thanks in Advance.

Regards,

RSY Narayan

Hi Subramanum,


Thanks for your inquiry. I have converted your shared HTML files to PDF using new DOM approach with Aspose.Pdf for Java 9.7.1. Please find attached output PDF files.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,

Thanks for your response.

Currently, We are using below jars on production.

1. aspose-pdf-2.9.0-jdk16.jar

2. aspose-pdf-kit-3.8.0.jar

3. itext-2.0.8.jar

4. iText-5.0.5.jar

So, we can't use Aspose.Pdf for Java 9.7.1 file on production directly. We have plan for implementing with latest jars on production but not now.

Could you please provide the solution for converting HTML to PDF as per HTML files by using mentioned jars those are we are using on production currently.

Thanks in advance.

Regards,

RSY Narayan

Hi Narayan,

Thanks for your feedback. Please note we use a single code base for our APIs, all fixes and enhancements are made in latest release. So I am afraid we can not provide you fix/solution in old version. It is recommend to upgrade to latest version of Aspose.Pdf for Java, it will help you to accomplish the task.

Moreover, please note Aspose.Pdf.Kit for Java has been moved com.aspose.pdf.facades package and Aspose.Pdf for Java 3.x.x moved to aspose.pdf package in merged version of Aspose.Pdf for Java. Please check following documentation link for migration details from old versions and API changes in merged version releases. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,

Thanks for your response. Now we are using valid license file and as per your suggestion, I am referring aspose.pdf-9.7.1-jdk16.jar. I hope the jar file is running for Java 6 version.

My Code:-

public class asposeHtmlToPDF {

public static void main (String args[]){
try{

String basePath = "C:/Users/502016937/Desktop/";
com.aspose.pdf.HtmlLoadOptions htmloptions = new com.aspose.pdf.HtmlLoadOptions(basePath);
// htmloptions.setUseNewConversionEngine(true);
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(basePath + "201504090000022.html", htmloptions);
doc.save("C:/Users/502016937/Desktop/201504090000022.pdf");
}catch (Exception e)
{
e.printStackTrace();
}
}

}

Currently I am getting the error -

class com.aspose.pdf.internal.p235.z9: At most 4 text fragments can be added in evaluation mode.
com.aspose.pdf.TextBuilder.m1(Unknown Source)
com.aspose.pdf.TextBuilder.appendText(Unknown Source)
com.aspose.pdf.z11.m1(Unknown Source)
com.aspose.foundation.rendering.z17.accept(Unknown Source)
com.aspose.foundation.rendering.z14.accept(Unknown Source)
com.aspose.foundation.rendering.z11.accept(Unknown Source)
com.aspose.foundation.rendering.z14.accept(Unknown Source)
com.aspose.foundation.rendering.z11.accept(Unknown Source)
com.aspose.foundation.rendering.z14.accept(Unknown Source)
com.aspose.foundation.rendering.z11.accept(Unknown Source)
com.aspose.foundation.rendering.z14.accept(Unknown Source)
com.aspose.foundation.rendering.z31.accept(Unknown Source)
com.aspose.pdf.z11.m1(Unknown Source)
com.aspose.pdf.ApsUsingConverter.m1(Unknown Source)
com.aspose.pdf.z72.m1(Unknown Source)
com.aspose.pdf.ADocument.m1(Unknown Source)
com.aspose.pdf.ADocument.(Unknown Source)
com.aspose.pdf.Document.(Unknown Source)
htmltopdf.asposeHtmlToPDF.main(asposeHtmlToPDF.java:23)
at com.aspose.pdf.TextBuilder.m1(Unknown Source)
at com.aspose.pdf.TextBuilder.appendText(Unknown Source)
at com.aspose.pdf.z11.m1(Unknown Source)
at com.aspose.foundation.rendering.z17.accept(Unknown Source)
at com.aspose.foundation.rendering.z14.accept(Unknown Source)
at com.aspose.foundation.rendering.z11.accept(Unknown Source)
at com.aspose.foundation.rendering.z14.accept(Unknown Source)
at com.aspose.foundation.rendering.z11.accept(Unknown Source)
at com.aspose.foundation.rendering.z14.accept(Unknown Source)
at com.aspose.foundation.rendering.z11.accept(Unknown Source)
at com.aspose.foundation.rendering.z14.accept(Unknown Source)
at com.aspose.foundation.rendering.z31.accept(Unknown Source)
at com.aspose.pdf.z11.m1(Unknown Source)
at com.aspose.pdf.ApsUsingConverter.m1(Unknown Source)
at com.aspose.pdf.z72.m1(Unknown Source)
at com.aspose.pdf.ADocument.m1(Unknown Source)
at com.aspose.pdf.ADocument.(Unknown Source)
at com.aspose.pdf.Document.(Unknown Source)
at htmltopdf.asposeHtmlToPDF.main(asposeHtmlToPDF.java:23)

I am attaching the sample html file. Rename the file txt to HTML. I am assuming that need to set the license file.

Could you please check the problem and if any error in code then please send me correct code.

Thanks in Advance.

Regards,

RSY Narayan

Hi Narayan,

Thanks for your feedback. The exception shows that you are evaluating JAR without a license. As the Aspose.Pdf evaluation version has two limitations, evaluation watermark and at most four elements of any collection can be viewed.

If you have a valid license then please apply it before instantiating any object of Aspose.Pdf jar. Otherwise make a request for 30 days temporary license and apply it to evaluate our product without any limitation. Hopefully your issue will be resolved.

Please feel free to contact us for any further assistance.

Best Regards,