Skip to content

Commit

Permalink
Fixes #133, #105: Set compatibity mode setting to turn off compatibil…
Browse files Browse the repository at this point in the history
…ity mode.
  • Loading branch information
ekimbernow authored and drmacro committed Jun 9, 2024
1 parent 72b7fa2 commit 9efbf5f
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTCompat;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTCompatSetting;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFldChar;
Expand Down Expand Up @@ -451,7 +452,7 @@ private void constructDoc(XWPFDocument doc, XmlObject xml) throws DocxGeneration
cursor.pop();
cursor.push();
cursor.toChild(new QName(DocxConstants.SIMPLE_WP_NS, "body"));

setDocSettings(doc, xml);
handleBody(doc, cursor.getObject());

cursor.pop();
Expand All @@ -462,7 +463,6 @@ private void constructDoc(XWPFDocument doc, XmlObject xml) throws DocxGeneration
setupPageSequence(doc, cursor.getObject());
} else {
CTDocument1 document = doc.getDocument();
setDocSettings(doc, xml);
CTBody body = (document.isSetBody() ? document.getBody() : document.addNewBody());
@SuppressWarnings("unused")
CTSectPr sectPr = (body.isSetSectPr() ? body.getSectPr() : body.addNewSectPr());
Expand All @@ -479,12 +479,17 @@ private void constructDoc(XWPFDocument doc, XmlObject xml) throws DocxGeneration
* @param xml Simple ML doc
*/
private void setDocSettings(XWPFDocument doc, XmlObject xml) {
// Issue #133: Turn off compatibility mode.
XWPFSettings settings = doc.getSettings();
CTSettings ctSettings = settings.getCTSettings();
CTCompat compat = ctSettings.addNewCompat();
// This may be all we need to do.


CTCompatSetting compatSetting = compat.addNewCompatSetting();
// Name, URI, and value come from inspecting working Word docs.
// I do not know where these values are documented.
compatSetting.setName("compatibilityMode");
compatSetting.setUri("http://schemas.microsoft.com/office/word");
compatSetting.setVal("15");
}

/**
Expand Down

0 comments on commit 9efbf5f

Please sign in to comment.