Java Code Examples for org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart#addTargetPart()
The following examples show how to use
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart#addTargetPart() .
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: Docx4jUtils.java From docx4j-template with Apache License 2.0 | 6 votes |
private void insertDocx(MainDocumentPart main, byte[] bytes, int chunkId) { try { AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + chunkId + ".docx")); // afiPart.setContentType(new ContentType(CONTENT_TYPE)); afiPart.setContentType(new ContentType(ContentTypes.APPLICATION_XML)); afiPart.setBinaryData(bytes); Relationship altChunkRel = main.addTargetPart(afiPart); CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk(); chunk.setId(altChunkRel.getId()); main.addObject(chunk); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory, headerPart, content, isUnderLine, underLineSz, jcEnumeration)); return rel; }
Example 3
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPageNumPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { FooterPart footerPart = new FooterPart(); footerPart.setPackage(wordprocessingMLPackage); footerPart.setJaxbElement(createFooterWithPageNr(factory)); return t.addTargetPart(footerPart); }
Example 4
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getFtr(wordprocessingMLPackage, factory, footerPart)); return rel; }
Example 5
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); // After addTargetPart, so image can be added properly headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, factory, headerPart)); return rel; }
Example 6
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, JcEnumeration jcEnumeration) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory, footerPart, content, jcEnumeration)); return rel; }
Example 7
Source File: Docx4J_简单例子.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, JcEnumeration jcEnumeration) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory, headerPart, content, jcEnumeration)); return rel; }
Example 8
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPageNumPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { FooterPart footerPart = new FooterPart(); footerPart.setPackage(wordprocessingMLPackage); footerPart.setJaxbElement(createFooterWithPageNr(factory)); return t.addTargetPart(footerPart); }
Example 9
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getFtr(wordprocessingMLPackage, factory, footerPart)); return rel; }
Example 10
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); // After addTargetPart, so image can be added properly headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, factory, headerPart)); return rel; }
Example 11
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, JcEnumeration jcEnumeration) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory, footerPart, content, jcEnumeration)); return rel; }
Example 12
Source File: Docx4J_简单例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, JcEnumeration jcEnumeration) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory, headerPart, content, jcEnumeration)); return rel; }
Example 13
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPageNumPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { FooterPart footerPart = new FooterPart(); footerPart.setPackage(wordprocessingMLPackage); footerPart.setJaxbElement(createFooterWithPageNr( wordprocessingMLPackage, factory, isUnderLine, underLineSz, jcEnumeration)); return t.addTargetPart(footerPart); }
Example 14
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, boolean isUnderLine, String underLineSize) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getFtr(wordprocessingMLPackage, factory, footerPart, isUnderLine, underLineSize)); return rel; }
Example 15
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createHeaderPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, boolean isUnderLine, String underLineSize) throws Exception { HeaderPart headerPart = new HeaderPart(); Relationship rel = t.addTargetPart(headerPart); // After addTargetPart, so image can be added properly headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, factory, headerPart, isUnderLine, underLineSize)); return rel; }
Example 16
Source File: Docx4J_例子2.java From docx4j-template with Apache License 2.0 | 5 votes |
public Relationship createTextFooterPart( WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception { FooterPart footerPart = new FooterPart(); Relationship rel = t.addTargetPart(footerPart); footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory, footerPart, content, isUnderLine, underLineSz, jcEnumeration)); return rel; }
Example 17
Source File: DocxBuilder.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public void createFootnote(String fnComment, R r, MainDocumentPart mdp) throws Exception{ // Setup FootnotesPart if necessary, // along with DocumentSettings FootnotesPart footnotesPart = mdp.getFootnotesPart(); if (footnotesPart==null) { // that'll be the case in this example // initialise it footnotesPart = new FootnotesPart(); mdp.addTargetPart(footnotesPart); CTFootnotes footnotes = (CTFootnotes)XmlUtils.unwrap( XmlUtils.unmarshalString(footnotePartXML)); footnotesPart.setJaxbElement(footnotes); // Usually the settings part contains footnote properties; // so add these if not present DocumentSettingsPart dsp =mdp.getDocumentSettingsPart(); if (dsp==null) { // create it dsp = new DocumentSettingsPart(); mdp.addTargetPart(dsp); } CTSettings settings = dsp.getContents(); if (settings ==null) { settings = wmlObjectFactory.createCTSettings(); dsp.setJaxbElement(settings); } CTFtnDocProps ftndocprops = settings.getFootnotePr(); if (ftndocprops==null ) { String openXML = "<w:footnotePr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" + "<w:footnote w:id=\"-1\"/>" // these 2 numbers are special, and correspond with string footnotePartXML below + "<w:footnote w:id=\"0\"/>" +"</w:footnotePr>"; settings.setFootnotePr( (CTFtnDocProps)XmlUtils.unmarshalString(openXML, Context.jc, CTFtnDocProps.class )); } } mdp.getPropertyResolver().activateStyle("FootnoteReference"); //mdp.getPropertyResolver().activateStyle("FootnoteText"); // OK, add a footnote addFootnote(footnoteCounter++, fnComment, footnotesPart, r); // Note: your footnote ids must be distinct; they don't need to be ordered (though Word will do that when you open the docx) }