Search in sources :

Example 6 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project flexmark-java by vsch.

the class DocxHelper method getNumPrFor.

// get a num pr for a list of given color (other than default)
// 
public BigInteger getNumPrFor(BigInteger baseNumID, Color color) {
    RPr rPr = getResolver().getEffectiveRPr(myOptions.PREFORMATTED_TEXT_STYLE);
    if (rPr != null && rPr.getColor() != null) {
        if (keepDiff(rPr.getColor(), color) == null) {
            return baseNumID;
        }
    }
    String colorID = String.format("%s:%s", baseNumID.toString(), color.getVal());
    final BigInteger numID = myNumPrColorMap.get(colorID);
    if (numID != null) {
        return numID;
    }
    // we create a copy of the baseNubPr and add the changed color property
    final NumberingDefinitionsPart ndp = myDocumentPart.getNumberingDefinitionsPart();
    try {
        final Numbering numbering = ndp.getContents();
        final List<Numbering.Num> num = numbering.getNum();
        final List<Numbering.AbstractNum> abstractNumList = numbering.getAbstractNum();
        for (Numbering.AbstractNum abstractNum : abstractNumList) {
            if (abstractNum.getAbstractNumId().compareTo(baseNumID) == 0) {
            // we have our list to copy
            // TODO: create a copy and set the color it the list's rpr.
            }
        }
        return null;
    } catch (Docx4JException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) BigInteger(java.math.BigInteger) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 7 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project mdw-designer by CenturyLinkCloud.

the class DocxBuilder method getNdp.

private NumberingDefinitionsPart getNdp() throws InvalidFormatException {
    if (ndp == null) {
        ndp = new NumberingDefinitionsPart();
        wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
        ndp.setJaxbElement(Context.getWmlObjectFactory().createNumbering());
    }
    return ndp;
}
Also used : NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart)

Example 8 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project Java-Tutorial by gpcodervn.

the class ConvertInXHTMLFile method main.

public static void main(String[] args) throws Exception {
    String inputfilepath = System.getProperty("user.dir") + "/somedir/some.html";
    // String baseURL = "file:///C:/Users/jharrop/git/docx4j-ImportXHTML/somedir/";
    String baseURL = "file:///C:/Users/jharrop/git/docx4j-ImportXHTML/";
    String stringFromFile = FileUtils.readFileToString(new File(inputfilepath), "UTF-8");
    String unescaped = stringFromFile;
    // if (stringFromFile.contains("&lt;/") ) {
    // unescaped = StringEscapeUtils.unescapeHtml(stringFromFile);
    // }
    // XHTMLImporter.setTableFormatting(FormattingOption.IGNORE_CLASS);
    // XHTMLImporter.setParagraphFormatting(FormattingOption.IGNORE_CLASS);
    System.out.println("Unescaped: " + unescaped);
    // Setup font mapping
    RFonts rfonts = Context.getWmlObjectFactory().createRFonts();
    rfonts.setAscii("Century Gothic");
    XHTMLImporterImpl.addFontMapping("Century Gothic", rfonts);
    // Create an empty docx package
    // WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(System.getProperty("user.dir") + "/styled.docx"));
    NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
    wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
    ndp.unmarshalDefaultNumbering();
    // Convert the XHTML, and add it into the empty docx we made
    XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
    XHTMLImporter.setHyperlinkStyle("Hyperlink");
    wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(unescaped, baseURL));
    System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
    // System.out.println(
    // XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getNumberingDefinitionsPart().getJaxbElement(), true, true));
    wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/OUT_from_XHTML.docx"));
}
Also used : XHTMLImporterImpl(org.docx4j.convert.in.xhtml.XHTMLImporterImpl) NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) RFonts(org.docx4j.wml.RFonts) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) File(java.io.File)

Example 9 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project Java-Tutorial by gpcodervn.

the class DocxToXhtmlAndBack method main.

public static void main(String[] args) throws Exception {
    // String baseURL = "file:///C:/Users/jharrop/git/docx4j-ImportXHTML/images";
    Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
    try {
        getInputFilePath(args);
    } catch (IllegalArgumentException e) {
    }
    System.out.println(inputfilepath);
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(dir + inputfilepath));
    // XHTML export
    AbstractHtmlExporter exporter = new HtmlExporterNG2();
    HtmlSettings htmlSettings = new HtmlSettings();
    htmlSettings.setWmlPackage(wordMLPackage);
    htmlSettings.setImageDirPath(dir + inputfilepath + "_files");
    htmlSettings.setImageTargetUri(dir + inputfilepath + "_files");
    String htmlFilePath = dir + "/DocxToXhtmlAndBack.html";
    OutputStream os = new java.io.FileOutputStream(htmlFilePath);
    // javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(os);
    // exporter.html(wordMLPackage, result, htmlSettings);
    // os.flush();
    // os.close();
    Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_NONE);
    // XHTML to docx
    String stringFromFile = FileUtils.readFileToString(new File(htmlFilePath), "UTF-8");
    WordprocessingMLPackage docxOut = WordprocessingMLPackage.createPackage();
    NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
    docxOut.getMainDocumentPart().addTargetPart(ndp);
    ndp.unmarshalDefaultNumbering();
    XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(docxOut);
    XHTMLImporter.setHyperlinkStyle("Hyperlink");
    docxOut.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(stringFromFile, null));
    docxOut.save(new java.io.File(dir + "/DocxToXhtmlAndBack.docx"));
}
Also used : XHTMLImporterImpl(org.docx4j.convert.in.xhtml.XHTMLImporterImpl) NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) OutputStream(java.io.OutputStream) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) HtmlSettings(org.docx4j.convert.out.html.AbstractHtmlExporter.HtmlSettings) AbstractHtmlExporter(org.docx4j.convert.out.html.AbstractHtmlExporter) HtmlExporterNG2(org.docx4j.convert.out.html.HtmlExporterNG2) File(java.io.File)

Example 10 with NumberingDefinitionsPart

use of org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart in project flexmark-java by vsch.

the class ListItemBlockFormatProvider method getPPr.

@Override
public void getPPr(final PPr pPr) {
    if (myPCount == 0) {
        // Create object for numPr
        PPrBase.NumPr numPr = myDocx.getFactory().createPPrBaseNumPr();
        pPr.setNumPr(numPr);
        // Create object for numId
        PPrBase.NumPr.NumId numId = myDocx.getFactory().createPPrBaseNumPrNumId();
        numPr.setNumId(numId);
        // listNumId));
        numId.setVal(BigInteger.valueOf(myIdNum));
        // Create object for ilvl
        PPrBase.NumPr.Ilvl ilvl = myDocx.getFactory().createPPrBaseNumPrIlvl();
        numPr.setIlvl(ilvl);
        ilvl.setVal(BigInteger.valueOf(myListLevel));
    } else {
        // need to inherit indent from our base style
        final NumberingDefinitionsPart ndp = myDocx.getDocxDocument().getNumberingDefinitionsPart();
        PPrBase.Ind ind = ndp.getInd(String.valueOf(myIdNum), String.valueOf(myListLevel));
        if (ind != null) {
            final DocxHelper helper = myDocx.getHelper();
            helper.ensureInd(pPr);
            pPr.getInd().setLeft(helper.safeIndLeft(ind));
            pPr.getInd().setHanging(BigInteger.ZERO);
        }
    }
    super.getPPr(pPr);
}
Also used : NumberingDefinitionsPart(org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart) PPrBase(org.docx4j.wml.PPrBase)

Aggregations

NumberingDefinitionsPart (org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart)11 XHTMLImporterImpl (org.docx4j.convert.in.xhtml.XHTMLImporterImpl)4 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)4 File (java.io.File)3 OutputStream (java.io.OutputStream)2 BigInteger (java.math.BigInteger)2 AbstractHtmlExporter (org.docx4j.convert.out.html.AbstractHtmlExporter)2 HtmlSettings (org.docx4j.convert.out.html.AbstractHtmlExporter.HtmlSettings)2 HtmlExporterNG2 (org.docx4j.convert.out.html.HtmlExporterNG2)2 AttributesNode (com.vladsch.flexmark.ext.attributes.AttributesNode)1 URL (java.net.URL)1 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 PPrBase (org.docx4j.wml.PPrBase)1 RFonts (org.docx4j.wml.RFonts)1