I am now having another issue that might be too specific, but I figured I would inquire anyway. For reference, I am using docx4j-3.3.0 and docx4j-ImportXHTML-3.3.0.
One of my clients is reporting an issue that revolves around auto spacing and tables after converting to docx. The text that immediately follows a table (any table) is jumping around when he tries to edit it. It seems to only be happening in the first piece of content after the table. I have Word 2013, and I am not having the issue. He uses Word 2010, and I also have a colleague that uses 2010. Both of them are able to reproduce the issue. I have added some screenshots below that I hope will help show what I am referring to.
This is how it SHOULD look:
http://imgur.com/a/pldp8
This is what he is getting when he first opens the document. (Notice the top portion of a line of text that looks cut off on the 5th line below the table)
http://imgur.com/a/VmP5b
This is what it looks like when he tries to make any change in that paragraph:
http://imgur.com/a/e6lom
Here is the relevant code that sets the spacing. I have removed some of the surrounding code for brevity.
- Code: Select all
var spacing = factory.createPPrBaseSpacing();
var line = new Packages.java.math.BigInteger(240);
spacing.setAfterAutospacing(true);
spacing.setBeforeAutospacing(true);
spacing.setLine(line);
spacing.setLineRule(Packages.org.docx4j.wml.STLineSpacingRule.AUTO);
var styles = sdp.getJaxbElement();
var docDefaults = styles.getDocDefaults();
var defaultRPr = docDefaults.getRPrDefault();
var defaultPPr = docDefaults.getPPrDefault();
var rPr = defaultRPr.getRPr();
var pPr = defaultPPr.getPPr();
var keep = new Packages.org.docx4j.wml.BooleanDefaultTrue();
keep.setVal(true);
pPr.setSpacing(spacing);
pPr.setKeepLines(keep);
pPr.setKeepNext(keep);
I have already confirmed with that client that if I remove the following two lines of code, the issue does not appear, so it appears that it is related to auto spacing somehow.
- Code: Select all
spacing.setAfterAutospacing(true);
spacing.setBeforeAutospacing(true);
Finally, here is the relevant HTML for that table and the paragraph that follows it. (I commented out the BR tags because it was not properly escaping them when posting)
- Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<meta charset='UTF-8' />
<title></title>
</head>
<body>
<div class='document'>
<table width="100%" border="1" cellspacing="0"
style="border-collapse: collapse">
<tr>
<td width="15%" style="font-weight: bold; font-style: italic;">
Customer Contact</td>
<td width="35%"></td>
<td width="15%" style="font-weight: bold; font-style: italic;">
Project Code / PT</td>
<td width="35%"></td>
</tr>
<tr>
<td style="font-weight: bold; font-style: italic;">Phone</td>
<td></td>
<td style="font-weight: bold; font-style: italic;">OTN/SSR</td>
<td></td>
</tr>
<tr>
<td style="font-weight: bold; font-style: italic;">Email</td>
<td></td>
<td style="font-weight: bold; font-style: italic;">Quote
Number(s)</td>
<td> </td>
</tr>
</table>
<p>This Statement of Work is subject to the terms and conditions of
the <b style="color: red;"><agreement name></b> agreement
between <b style="color: red;"><master signing
entity></b> and <b style="color: red;"><customer signing
entity></b> executed on <b style="color: red;"><date></b>
including any amendments (the Agreement). Capitalized terms will
have the meanings given in this document or in the Agreement.
Unless specifically stated otherwise in this SOW, in the event of a
conflict between this SOW and the terms of the Agreement, the order
of precedence specified in the Agreement will apply. If there is no
order of precedence specified, the terms of the Agreement will
control.
<!--br-->
<!--br-->
Customer's signature or electronic authorization acknowledges that
Customer has reviewed and agrees to this SOW. The effective date
is, in the case where manual signature is required, the date on
which the last party signs this SOW, or otherwise the date that
makes available or provides the order confirmation to
Customer (SOW Effective Date).
<!--br-->
<!--br-->
</p>
</div>
</body>
</html>
They are working around the issue by manually changing the setKeepLines and setKeepNext within Word for now, but I would like to make a fix on the back end. As you can see in the code above, even when I apply that fix to the docDefaults on my side, they still have the issue.
Since I am sending the entire document over in one giant XHTML string, it makes it difficult for me to split that up. Any fixes I can make would have to be able to be applied to the entire document using docx4j or modified in the corresponding HTML.
Do you have any ides or suggestions about how I can work around this issue, or if it is a bug? I understand that using Word 2010 makes it harder to test and resolve, but as they are a large company, they cannot easily roll out an Office upgrade to solve it that way.
Any help or suggestions you can provide would be greatly appreciated. Thanks!