I am converting HTML file into PDF using Aspose.words. But it is not supporting Word wrap functionality for the same.
Thanks for your inquiry. We will appreciate it if you please ZIP and attach the following resources to the post for testing. We will look into these and will guide you accordingly.
- Your input document
- Output document, showing undesired behavior
- Expected output document. You may generated it using MS Word
- Please share your existing sample code (without compilation errors) that helps us to reproduce your problem on our end.
Thanks for the quick support.
PFA sample HTML file, PDF File generated from Aspose.words and Aspose.pdf and sample code.
I am not getting word wrap functionality with Aspose.words but it can be done with Aspose.pdf.
I am using Aspose.words 17.8 to convert HTML to PDF as it takes less time to convert HTML to PDF.
TestWordWrap.zip (83.9 KB)
Thanks for your inquiry. Please try following code snippet, hopefully it will help you to accomplish the task.
for (Section sectoin : doc.getSections())
{
PageSetup ps = sectoin.getPageSetup();
ps.setOrientation(Orientation.LANDSCAPE);
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write("Page ");
builder.insertField("PAGE", null);
builder.write(" of ");
builder.insertField("NUMPAGES", null);
}
for (com.aspose.words.Table table : (Iterable<com.aspose.words.Table>)doc.getChildNodes(NodeType.TABLE,true))
{
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
}
OutputStream outputStream = new FileOutputStream("./Destination/TestWordWrap.pdf");
Hi Tilal,
From above code word is getting wrapped but column width is getting changed which is changing the formatting of my table. Please do suggest if you have any other approach for this. PFA PDF generated with word wrap form Aspose.words and Actual PDF.
Also please do suggest me which Aspose product should i use for this utility (Aspose.pdf or Aspose.words) to convert HTML to PDF.Files.zip (82.6 KB)
Thanks and Regards,
Sushant
Thanks for your feedback. If you do not want to wrap the table columns, then you can increase the document width and use following code snippet.
Furthermore, if you want to manipulate PDF document then it is recommended to use Aspose.Pdf for Java. However, if you want only HTML to PDF conversion then please use Aspose.Html for Java. It can manipulate HTML and render it to PDF.
for (Section sectoin : doc.getSections())
{
PageSetup ps = sectoin.getPageSetup();
ps.setOrientation(Orientation.LANDSCAPE);
ps.setPageWidth(com.aspose.words.ConvertUtil.inchToPoint(13));
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write("Page ");
builder.insertField("PAGE", null);
builder.write(" of ");
builder.insertField("NUMPAGES", null);
}
for (com.aspose.words.Table table : (Iterable<com.aspose.words.Table>)doc.getChildNodes(NodeType.TABLE,true))
{
table.setAllowAutoFit(false);
table.setPreferredWidth(PreferredWidth.fromPercent(100));
//table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
}
doc.updateTableLayout();
OutputStream outputStream = new FileOutputStream("TestWordWrap_179_java.pdf");
Thanks for this suggestion. Actually word wrapping functionality is working with this. But table is going outside the page. And I don’t want to change the page width for the same. Please do suggest me if there is any solution for this.
Also I didn’t find any documentation regarding Aspose.html. Can you please share me sample code and documentation for Aspose.HTML to convert HTML to PDF code.
Thanks and Regards,
Sushant
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you open the HTML in MS Word and save it to PDF, you will get the same output. However, you can change the table’s cell width according to your requirement.
We will answer your query about Aspose.HTML as soon as possible.