use of org.docx4j.wml.Styles in project docx4j-template by vindell.
the class ChangingTheStyleSheet method alterStyleSheet.
/**
* This method alters the default style sheet that is part of each document.
*
* To do this, we first retrieve the style sheet from the package and then
* get the Styles object from it. From this object, we get the list of actual
* styles and iterate over them.
* We check against all styles we want to alter and apply the alterations if
* applicable.
*
* @param wordMLPackage
*/
public static void alterStyleSheet() {
StyleDefinitionsPart styleDefinitionsPart = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart();
Styles styles = styleDefinitionsPart.getJaxbElement();
List<Style> stylesList = styles.getStyle();
for (Style style : stylesList) {
if (style.getStyleId().equals("Normal")) {
alterNormalStyle(style);
} else if (style.getStyleId().equals("Heading2")) {
alterHeading2Style(style);
} else if (style.getStyleId().equals("Heading1") || style.getStyleId().equals("Heading3") || style.getStyleId().equals("Title") || style.getStyleId().equals("Subtitle")) {
getRunPropertiesAndRemoveThemeInfo(style);
}
}
}
use of org.docx4j.wml.Styles in project Java-Tutorial by gpcodervn.
the class NumberingTest method getStyles.
public Styles getStyles() {
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
Styles styles = wmlObjectFactory.createStyles();
// Create object for style
Style style = wmlObjectFactory.createStyle();
styles.getStyle().add(style);
style.setStyleId("MyListStyle");
// Create object for pPr
PPr ppr = wmlObjectFactory.createPPr();
style.setPPr(ppr);
// Create object for numPr
PPrBase.NumPr pprbasenumpr = wmlObjectFactory.createPPrBaseNumPr();
ppr.setNumPr(pprbasenumpr);
// Create object for numId
PPrBase.NumPr.NumId pprbasenumprnumid = wmlObjectFactory.createPPrBaseNumPrNumId();
pprbasenumpr.setNumId(pprbasenumprnumid);
pprbasenumprnumid.setVal(BigInteger.valueOf(PREDEFINED_OL_NUMID));
// Create object for uiPriority
Style.UiPriority styleuipriority = wmlObjectFactory.createStyleUiPriority();
style.setUiPriority(styleuipriority);
styleuipriority.setVal(BigInteger.valueOf(99));
// Create object for name
Style.Name stylename = wmlObjectFactory.createStyleName();
style.setName(stylename);
stylename.setVal("MyListStyle");
style.setType("numbering");
// org.docx4j.model.PropertyResolver.init(PropertyResolver.java:173)
// currently requires a default p style
styles.getStyle().add(createNormal());
return styles;
}
use of org.docx4j.wml.Styles in project flexmark-java by vsch.
the class DocxRenderer method setDefaultStyleAndNumbering.
static void setDefaultStyleAndNumbering(WordprocessingMLPackage out, final DataHolder options) {
try {
// (main doc part it if necessary)
MainDocumentPart documentPart = out.getMainDocumentPart();
if (documentPart == null) {
try {
documentPart = new MainDocumentPart();
out.addTargetPart(documentPart);
} catch (InvalidFormatException e) {
e.printStackTrace();
}
}
if (documentPart.getStyleDefinitionsPart() == null) {
Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
final Styles styles = (Styles) XmlUtils.unmarshalString(STYLES_XML.getFrom(options));
((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart).setJaxbElement(styles);
// NB - add it to main doc part, not package!
documentPart.addTargetPart(stylesPart);
assert documentPart.getStyleDefinitionsPart() != null : "Styles failed to set";
}
if (documentPart.getNumberingDefinitionsPart() == null) {
// add it
Part numberingPart = new org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart();
final Numbering numbering = (Numbering) XmlUtils.unmarshalString(NUMBERING_XML.getFrom(options));
((org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) numberingPart).setJaxbElement(numbering);
// NB - add it to main doc part, not package!
documentPart.addTargetPart(numberingPart);
assert documentPart.getNumberingDefinitionsPart() != null : "Numbering failed to set";
}
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Aggregations