Aspose.pdf for HTML to PDF conversion

I am converting HTML to PDF using Aspose.pdf 17.8 and facing some issue related to Aspose.pdf

  1. It is taking too much time to convert HTML to PDF. approx 25 second to generate PDF file.
  2. Table header doesn’t appear if that table splits into 2 pages.

And also I am facing some issues in Linux box with the Aspose,pdf like Font change, text is going out of column etc.

Also I tried to covert this using Aspose.words as it takes less time 4-5 seconds. But in this I am facing word wrap issue.

PFA code for the conversion.
HtmlToPDFConverter.zip (763 Bytes)

Please do suggest me the proper product to use from Aspose for this utility. And also suggest me the solution for above issues.

@ksushant,

Thanks for contacting support.

I have tested the scenario of HTML to PDF conversion and have observed that API takes different time when performing conversion and it depends upon the structure of input HTML file. However in order to test your scenario, we need the input HTML document.

In order to resolve such issues, please try installing the fonts referenced inside HTML file and in case you still face the same problem, please share the sample file and font files. We are sorry for your inconvenience.

Hi Team,

sample3.zip (1.1 KB)

PFA sample HTML file. It is the simple HTML file but it is also taking almost 16 sec to convert into PDF with above code. Please test at your end and let me know the timing required for this conversion.

Also, For font issue I have not use any specific fonts file. I am getting exact PDF file generated in my windows system with the same file but I am facing issues while it is generated in Linux machine.

Please help me through this.

@ksushant,

Thanks for sharing the sample file. I have tested the scenario and have managed to replicate the same problem that HTML to PDF conversion process takes around 14 seconds. For the sake of correction, I have logged it as PDFJAVA-37112 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

One of the reasons is that fonts used inside PDF file are not available on Linux machine, whereas they exist over Windows machine. In order to generate correct output, please install required fonts over Linux and then test the scenario.

Furthermore, when creating PDF files from scratch or manipulating existing PDF files on Non-Windows platform, you need to have fonts installed on your system and you need to specify the path where fonts used inside PDF file are installed. You can use following methods to get system folder of fonts or set font path to font folders. Furthermore, the code snippet which you have shared earlier is based on legacy aspose.pdf package and we recommend using new Document Object Model of com.aspose.pdf package.

The following details are based on new DOM approach.

Document.getLocalFontPath () - shows the system folder in which project will look for fonts.
Document.setLocalFontPath (String) - Setting font path to custom folder

// Set font folder path String path = “/usr/share/fonts/truetype/msttcorefonts/”;
// Adding a single font directory //
com.aspose.pdf.Document.addLocalFontPath(path);
// setting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);

can we not add a path from classpath ? Does fonts need to be installed on system? can’t it read from the jar’s classpath ?

@yogesh1001

The API looks for installed fonts in the system while rendering documents. Or, you may specify custom fonts paths by using the code snippet shared in previous replies if some fonts are not installed in the system.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

is the custom font can be class-path inside the jar or it has to be system path ?

@yogesh1001

We have logged a ticket with ID PDFJAVA-38211 to investigate it in detail. We will let you know as soon as some significant details will be available in this regard.