We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Different margin behavior between 10.3 and 10.8

Hi, I'm trying to upgrade our Aspose.Words Java version from 10.3 to 10.8 and I'm seeing different output just by using the new jar (with no code change on my part). First, it seems like the default behavior on table borders changed. I now have to call table.clearBorders() explicitly so that my tables won't have borders. Second, and this is what I need help on, the left margin changed on parts of my document. Basically, I'm getting the contents of a document stored in the database and including it in another document. But before I include it in the document, I need to add a heading. When I add the heading the left margin is increased in the included document, but only on the first page (margin in the succeeding pages is fine). If I don't add the heading, the left margin is fine even in the first page.

Here's the relevant piece of code that creates the document in the database that needs to be included:

byte[] fileContent = getFileContent(); //we use iBatis to get the contents stored in the database

Document includeDoc = new Document(new ByteArrayInputStream(fileContent));

I use a static helper method to write the heading:

String fileTitle = getFileTitle(); //the title is read from the database

AsposeDocumentHelper.writeHeading( includeDoc, fileTitle, StyleIdentifier.HEADING_2, true);

This is the body of writeHeading:

public static void writeHeading(Document doc, String str, int heading, boolean visible) throws Exception {

double rowHeight = 0.01;

int heightRule = HeightRule.EXACTLY;

double cellWidth = 5.5 * 72;

DocumentBuilder builder = new DocumentBuilder(doc);



if(visible) {

rowHeight = 0.38 * 72;

heightRule = HeightRule.AT_LEAST;


if(str.length() > 56) rowHeight += 0.4 * 72;

Paragraph para1 = new Paragraph(doc);


Run run1 = new Run(doc);



Cell cell1 = new Cell(doc);



Row row1 = new Row(doc);




Table tab1 = new Table(doc);





Why does calling writeHeading above change the margin on the first page of the included document? Thanks in advance.

I think I figured it out. If I change the setWidth call above to setPreferredWidth, as such:


and I also added tab1.setPreferredWidth( PreferredWidth.AUTO); towards the end of the helper method, then I got the behavior I wanted. The contents after the "heading" don't get shifted to the right with a big left margin.


Thanks for your request. It is perfect that you managed to resolve the problem. But anyways, I think, the following article could be useful for you”


Best regards,

Hi there,

You may also find the following article useful:


Thank you so much for all the replies! I definitely should read this migration article.