Can I get some guidence on how to convert html file to pdf?
You can use Aspose.Words for Java to convert HTML to PDF. Following code example shows how to convert HTML to PDF. Hope this helps you.
// Load the document from disk.
Document doc = new Document(dataDir + "input.html");
// Save the document in PDF format.
dataDir = dataDir + "output.pdf";
doc.save(dataDir);
I tried converting html to pdf file. It worked but the pdf file does not have a line from the original file. Also some table headers are which were originally single line are converted to two lines. Is there any way to get the pdf file with all the lines in same alignment?
Please ZIP and attach your input, problematic and expected output documents here for testing. We will investigate the issue and provide you more information on it.
I have attached the sample html file. The html file contains the table header in single line but in the converted pdf , the header is converted to two lines. The line following the table is also missing.
sample html:
samplehtml.html.zip (2.4 KB)
obtained pdf:
sampleHTML-to-PDF.pdf.zip (40.8 KB)
We have tested the scenario and noticed that the line height become doubled after HTML to PDF conversion. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22018. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.
We have not found two lines in output PDF. Could you please share the screenshot of problematic sections of output document? We will then provide you more information on it.
sample html: samplehtml.html.zip (2.4 KB)
obtained pdf: sampleHTML-to-PDF.pdf.zip (40.8 KB)
Table header comparison:
in_html.png (60.4 KB)
in_pdf.png (21.5 KB)
Some lines are wraped into two lines : in pdf line.png (3.6 KB)
Please note that Aspose.Words mimics the behavior of MS Word. If you convert your HTML document to PDF using MS Word, you will get the same output.
Please ZIP and attach your expected output PDF here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.
We suggest you please set the table’s width as shown below to get the desired output. Hope this helps you.
Document doc = new Document(MyDir + "samplehtml.html");
for(Table table :(Iterable<Table>)doc.getChildNodes(NodeType.TABLE, true))
{
table.setPreferredWidth(PreferredWidth.fromPercent(100));
}
doc.save(MyDir + "21.3.docx");
Thanks for the suggestion.
It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue WORDSNET-22018 as ‘Not a Bug’.
The converted pdf does not contain a line which is present in the html file. Can I please get some assistance on how to convert html to pdf with all the contained line?
We have not found the share issue in output PDF. Could you please check the attach output PDF file and share the screenshot of problematic section? We will test this issue again and provide you more information on it. html to pdf.pdf (90.1 KB)
The line below the table is not found n converted pdf
in html file : in html.png (14.3 KB)
in pdf file : inpdf.png (40.7 KB)
Please note that Aspose.Words mimics the behavior of MS Word. If you convert your HTML to PDF using MS Word, you will get the same output.
Moreover, if we open the HTML in browser e.g. Google Chrome or Microsoft Edge, we do not see any border lines.