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);

builder.moveToDocumentStart();

builder.write(ECVConstants.TMP_HEADING_STR);

if(visible) {

rowHeight = 0.38 * 72;

heightRule = HeightRule.AT_LEAST;

}

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

Paragraph para1 = new Paragraph(doc);

para1.getParagraphFormat().setStyleIdentifier(heading);

Run run1 = new Run(doc);

run1.setText(str);

para1.appendChild(run1);

Cell cell1 = new Cell(doc);

cell1.getCellFormat().setWidth(cellWidth);

cell1.appendChild(para1);

Row row1 = new Row(doc);

row1.getRowFormat().setHeight(rowHeight);

row1.getRowFormat().setHeightRule(heightRule);

row1.getCells().add(cell1);

Table tab1 = new Table(doc);

tab1.getRows().add(row1);

tab1.clearBorders();

doc.getFirstSection().getBody().prependChild(tab1);

}

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:

cell1.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(cellWidth));

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.

Hi

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”

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/specifying-table-and-cell-widths.html

Best regards,

Hi there,


You may also find the following article useful:
http://www.aspose.com/documentation/java-components/aspose.words-for-java/howto-migrate-to-aspose-words-10-5-or-higher.html

Thanks,

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