Column width for html->pdf conversions

I am trying to convert an html report to pdf (Java aspose.word product) but the column widths and wrapping are not being converted properly. I am wondering if I can control this to make a readable pdf? With a prior product, I was able to use setHtmlWidth() to help control but event without that, the results were better. I am hoping to use this product so please let me know what I can do.

I tried using PdfSaveOptions with (setZoomBehaviour./setZoomFactor) but I don’t see any differences. The code I am using follows …

Document doc = new Document("testHtml.html");            
// easiest way to save to file
//doc.save("aspose.doc");  
            
// using output stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
            
// trying options
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_A_1_B);  
options.setZoomBehavior(PdfZoomBehavior.FIT_WIDTH);
options.setZoomFactor(50);
                
doc.save(out, options);
byte[] dataForWriting = out.toByteArray();
FileUtils.writeByteArrayToFile(new File("testHtml.pdf"), dataForWriting);

I have also tried with just this …

Document doc = new Document("testHtml.html");
// easiest way to save to file
//doc.save("aspose.doc");  

Please find before (html) and after (pdf) attached…

testHtml.zip (54.4 KB)

@alcea The problem occurs because page width is too small for the table in your HTML. You can adjust page size to get a better result. For example see the following code:

Document doc = new Document();
doc.getFirstSection().getPageSetup().setOrientation(Orientation.LANDSCAPE);
doc.getFirstSection().getPageSetup().setPaperSize(PaperSize.A3);
doc.getFirstSection().getPageSetup().setLeftMargin(36);
doc.getFirstSection().getPageSetup().setRightMargin(36);

DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml(Files.readString(Path.of("C:\\Temp\\in.html")));
doc.save("C:\\Temp\\out.pdf");

not sure if I like the product or the support better
Thanks so much

1 Like