@pkvogt
Issue Overview
When a DOCX document contains a table that is wider than the printable page area (e.g., the table width exceeds the right margin), the conversion to TIFF (or PDF) with Aspose.Words for Java cuts off the overflowing columns. The online converter shows the same behaviour because it uses the same rendering engine.
Why It Happens
- Aspose.Words renders the document exactly as it is laid out in Word.
- If a table’s total width is greater than the page width minus the left/right margins, the rendering engine draws the table up to the page edge and discards content that lies outside the page bounds.
- This is the same behaviour you would see when printing the DOCX from Microsoft Word.
How to Prevent Columns from Being Cut Off
1. Make the Table Fit the Page Width (recommended)
Force the table to auto‑fit to page before saving:
// Load the DOCX
Document doc = new Document("file_with_table.docx");
// Iterate through all tables in the document
for (Table table : (Iterable<Table>) doc.getChildNodes(NodeType.TABLE, true)) {
// Auto‑fit the table to the page width (respecting margins)
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_PAGE);
}
// Optional: recalculate layout after changes
doc.updatePageLayout();
// Save to TIFF
ImageSaveOptions tiffOptions = new ImageSaveOptions(SaveFormat.TIFF);
tiffOptions.setPageSize(PageSize.A4); // or keep original size
tiffOptions.setResolution(300); // DPI, adjust as needed
doc.save("output.tiff", tiffOptions);
What this does
AUTO_FIT_TO_PAGE
scales the columns proportionally so the entire table fits within the printable area defined by the page margins.
- No columns are lost – they are simply resized.
2. Use Fixed Column Widths (if you need exact sizes)
If you must keep specific column widths, set fixed column widths that are guaranteed to be smaller than the printable width:
double printableWidth = doc.getFirstSection().getPageSetup().getPageWidth()
- doc.getFirstSection().getPageSetup().getLeftMargin()
- doc.getFirstSection().getPageSetup().getRightMargin();
for (Table table : (Iterable<Table>) doc.getChildNodes(NodeType.TABLE, true)) {
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS); // disable auto‑fit
// Example: distribute printable width equally among columns
int columnCount = table.getFirstRow().getCells().getCount();
double colWidth = printableWidth / columnCount;
for (Row row : table.getRows()) {
for (Cell cell : row.getCells()) {
cell.getCellFormat().setPreferredWidth(colWidth);
cell.getCellFormat().setPreferredWidthType(PreferredWidthType.POINT);
}
}
}
doc.updatePageLayout();
- This approach gives you full control over each column’s width while ensuring the whole table stays inside the margins.
3. Adjust Page Setup Margins (if you can afford smaller margins)
Sometimes the document’s margins are unnecessarily wide. Reducing them gives more room for the table:
PageSetup ps = doc.getFirstSection().getPageSetup();
ps.setLeftMargin(20); // points
ps.setRightMargin(20);
doc.updatePageLayout();
Note: Changing margins affects the whole document, not only the table.
4. Use Save‑Option Settings that Respect Page Size
For PDF conversion you can explicitly tell the renderer to use the original page size:
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.setUsePdfPageSize(true); // keeps original page dimensions
doc.save("output.pdf", pdfOptions);
For TIFF you can enforce the same page size:
ImageSaveOptions tiffOptions = new ImageSaveOptions(SaveFormat.TIFF);
tiffOptions.setPageSize(PageSize.A4); // or doc.getPageInfo(0).getSize()
doc.save("output.tiff", tiffOptions);
5. Verify the Aspose.Words Version
The table‑auto‑fit logic has been stable for many releases, but always use the latest Aspose.Words for Java (or at least a version newer than 21.9) to benefit from bug‑fixes and improvements:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>24.9</version> <!-- replace with the latest available -->
</dependency>
If you are already on the latest version and the problem persists after applying the steps above, please let us know the exact version you are using (including the full build number).
Quick Checklist
 |
Action |
|
Load the document (Document doc = new Document("file.docx"); ) |
 |
Force tables to auto‑fit to page (table.autoFit(AutoFitBehavior.AUTO_FIT_TO_PAGE); ) |
 |
Call doc.updatePageLayout(); after modifications |
 |
Save using appropriate options (ImageSaveOptions for TIFF, PdfSaveOptions for PDF) |
 |
Use the latest Aspose.Words for Java |
Next Steps
- Apply the code snippet(s) above to your source document.
- Re‑run the conversion to TIFF (or PDF) and verify that all columns are now visible.
- If you still encounter clipping, please reply with:
- The exact Aspose.Words for Java version you are using.
- A minimal reproducible DOCX (you can redact sensitive data) that still shows the problem after applying the auto‑fit code.
- Any custom
SaveOptions
you are currently using.
We’ll be happy to dive deeper with you.
Useful Links
If you need any further assistance, feel free to ask!