org.docx4j.openpackaging.exceptions.InvalidFormatException Java Examples
The following examples show how to use
org.docx4j.openpackaging.exceptions.InvalidFormatException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 7 votes |
public void createHeaderReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } HeaderReference headerReference = factory.createHeaderReference(); headerReference.setId(relationship.getId()); headerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(headerReference); }
Example #2
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createHeaderReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } HeaderReference headerReference = factory.createHeaderReference(); headerReference.setId(relationship.getId()); headerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(headerReference); }
Example #3
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createFooterReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } FooterReference footerReference = factory.createFooterReference(); footerReference.setId(relationship.getId()); footerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(footerReference); }
Example #4
Source File: Docx4jTest.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 创建页眉引用关系 * * @param word * @param relationship * @throws InvalidFormatException */ public static void createHeaderReference( WordprocessingMLPackage word, Relationship relationship ) throws InvalidFormatException { List<SectionWrapper> sections = word.getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr==null ) { sectPr = factory.createSectPr(); word.getMainDocumentPart().addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } HeaderReference headerReference = factory.createHeaderReference(); headerReference.setId(relationship.getId()); headerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(headerReference); }
Example #5
Source File: Docx4jTest.java From docx4j-template with Apache License 2.0 | 6 votes |
/** * 创建页脚引用关系 * * @param word * @param relationship * @throws InvalidFormatException */ public static void createFooterReference( WordprocessingMLPackage word, Relationship relationship ) throws InvalidFormatException { List<SectionWrapper> sections = word.getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr==null ) { sectPr = factory.createSectPr(); word.getMainDocumentPart().addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } FooterReference footerReference = factory.createFooterReference(); footerReference.setId(relationship.getId()); footerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(footerReference); }
Example #6
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createFooterReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } FooterReference footerReference = factory.createFooterReference(); footerReference.setId(relationship.getId()); footerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(footerReference); }
Example #7
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createHeaderReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } HeaderReference headerReference = factory.createHeaderReference(); headerReference.setId(relationship.getId()); headerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(headerReference); }
Example #8
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 6 votes |
public void createFooterReference( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException { List<SectionWrapper> sections = wordprocessingMLPackage .getDocumentModel().getSections(); SectPr sectPr = sections.get(sections.size() - 1).getSectPr(); // There is always a section wrapper, but it might not contain a sectPr if (sectPr == null) { sectPr = factory.createSectPr(); t.addObject(sectPr); sections.get(sections.size() - 1).setSectPr(sectPr); } FooterReference footerReference = factory.createFooterReference(); footerReference.setId(relationship.getId()); footerReference.setType(HdrFtrRef.DEFAULT); sectPr.getEGHdrFtrReferences().add(footerReference); }
Example #9
Source File: AddingPageNrToFooter.java From docx4j-template with Apache License 2.0 | 5 votes |
/** * As in the previous example, this method creates a footer part and adds it to * the main document and then returns the corresponding relationship. * * @return * @throws InvalidFormatException */ private static Relationship createFooterPart() throws InvalidFormatException { FooterPart footerPart = new FooterPart(); footerPart.setPackage(wordMLPackage); footerPart.setJaxbElement(createFooterWithPageNr()); return wordMLPackage.getMainDocumentPart().addTargetPart(footerPart); }
Example #10
Source File: CreateBlockTest.java From docx4j-export-FO with Apache License 2.0 | 5 votes |
@Test public void test() throws SAXException, IOException, TransformerException, InvalidFormatException { /* Here we want to test white space handling in * protected static DocumentFragment createBlock(WordprocessingMLPackage wmlPackage, RunFontSelector runFontSelector, NodeIterator childResults, boolean sdt, PPr pPrDirect, PPr pPr, RPr rPr, RPr rPrParagraphMark) */ // We need NodeIterator, simulating the results from XSLT File f = new File("src/test/java/org/docx4j/convert/out/fo/nodes.fo"); DocumentBuilder db = XmlUtils.getNewDocumentBuilder(); Document doc = db.parse(f); NodeIterator childResults = XPathAPI.selectNodeIterator(doc, "/*"); //System.out.println(childResults.nextNode().getNodeName()); // Other params don't matter FOConversionContext context = null; String pStyleVal = "styleX"; boolean sdt = false; PPr pPrDirect = new PPr(); PPr pPr = new PPr(); RPr rPr = new RPr(); RPr rPrParagraphMark = new RPr(); WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.createPackage(); RunFontSelector runFontSelector = FOConversionContext.createRunFontSelector(wmlPackage); DocumentFragment df = XsltFOFunctions.createBlock( wmlPackage, runFontSelector, pStyleVal, childResults, sdt, pPrDirect, pPr, rPr, rPrParagraphMark); System.out.println(XmlUtils.w3CDomNodeToString(df)); }
Example #11
Source File: AddingAFooter.java From docx4j-template with Apache License 2.0 | 3 votes |
/** * This method creates a footer part and set the package on it. Then we add some * text and add the footer part to the package. Finally we return the * corresponding relationship. * * @return * @throws InvalidFormatException */ private static Relationship createFooterPart() throws InvalidFormatException { FooterPart footerPart = new FooterPart(); footerPart.setPackage(wordMLPackage); footerPart.setJaxbElement(WmlElementUtils.createFooter("Text")); return wordMLPackage.getMainDocumentPart().addTargetPart(footerPart); }
Example #12
Source File: TextBoxTest.java From docx4j-export-FO with Apache License 2.0 | 2 votes |
private static WordprocessingMLPackage createTextBoxDocx(boolean w10WrapEl, String style) throws InvalidFormatException { // speedup // String regex = ".*(calibri|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*"; String regex = ".*(calibri|cour|arial).*"; PhysicalFonts.setRegex(regex); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); P p = new P(); mdp.getContent().add(p); R r = Context.getWmlObjectFactory().createR(); r.getContent().add( // Absolute position to the right of column produces: // margin-left:108pt // mso-position-horizontal:absolute <------------ // mso-position-horizontal-relative:text // mso-wrap-style:square // style="position:absolute;margin-left:108pt;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" createPict(w10WrapEl, style, createContent("text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content "))); // Relative position is done in percentages.. // mso-left-percent:600 // mso-position-horizontal-relative:left-margin-area // mso-width-relative:margin // style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal-relative:left-margin-area;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" p.getContent().add( r); p.getContent().add(addFiller()); return wordMLPackage; }