Java Code Examples for org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart#setJaxbElement()

The following examples show how to use org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart#setJaxbElement() . 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 5 votes vote down vote up
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 2
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
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 3
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
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 4
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
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 5
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
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 6
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
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 7
Source File: WordProcessor.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
private void setHdr(HeaderPart headerPart) throws Docx4JException, IOException, JAXBException  {
	ImagePngPart imagePart = new ImagePngPart(new PartName("/media/background.png"));
	try (InputStream in = new FileInputStream(imageFile)){
		imagePart.setBinaryData(in);
	}
	Relationship rel = headerPart.addTargetPart(imagePart, AddPartBehaviour.REUSE_EXISTING); // the one image is shared by the 3 header parts

	String openXML = "<w:hdr mc:Ignorable=\"w14 wp14\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
			+ "<w:p>"
			+ "<w:pPr>"
			+ "<w:pStyle w:val=\"Header\"/>"
			+"</w:pPr>"
			+ "<w:r>"
			+ "<w:rPr>"
			+ "<w:noProof/>"
			+"</w:rPr>"
			+ "<w:pict>"
			+ "<v:shapetype coordsize=\"21600,21600\" filled=\"f\" id=\"_x0000_t75\" o:preferrelative=\"t\" o:spt=\"75\" path=\"m@4@5l@4@11@9@11@9@5xe\" stroked=\"f\">"
			+ "<v:stroke joinstyle=\"miter\"/>"
			+ "<v:formulas>"
			+ "<v:f eqn=\"if lineDrawn pixelLineWidth 0\"/>"
			+ "<v:f eqn=\"sum @0 1 0\"/>"
			+ "<v:f eqn=\"sum 0 0 @1\"/>"
			+ "<v:f eqn=\"prod @2 1 2\"/>"
			+ "<v:f eqn=\"prod @3 21600 pixelWidth\"/>"
			+ "<v:f eqn=\"prod @3 21600 pixelHeight\"/>"
			+ "<v:f eqn=\"sum @0 0 1\"/>"
			+ "<v:f eqn=\"prod @6 1 2\"/>"
			+ "<v:f eqn=\"prod @7 21600 pixelWidth\"/>"
			+ "<v:f eqn=\"sum @8 21600 0\"/>"
			+ "<v:f eqn=\"prod @7 21600 pixelHeight\"/>"
			+ "<v:f eqn=\"sum @10 21600 0\"/>"
			+"</v:formulas>"
			+ "<v:path gradientshapeok=\"t\" o:connecttype=\"rect\" o:extrusionok=\"f\"/>"
			+ "<o:lock aspectratio=\"t\" v:ext=\"edit\"/>"
			+"</v:shapetype>"
			+ "<v:shape id=\"WordPictureWatermark835936646\" o:allowincell=\"f\" o:spid=\"_x0000_s2050\" style=\"position:absolute;margin-left:0;margin-top:0;width:640px;height:400px;z-index:-251657216;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin\" type=\"#_x0000_t75\">"
			+ "<v:imagedata blacklevel=\"22938f\" gain=\"19661f\" o:title=\"docx4j-logo\" r:id=\"" + rel.getId() + "\"/>"
			+"</v:shape>"
			+"</w:pict>"
			+"</w:r>"
			+"</w:p>"
			+"</w:hdr>";

	Hdr hdr = (Hdr)XmlUtils.unmarshalString(openXML);
	headerPart.setJaxbElement(hdr);
}
 
Example 8
Source File: WatermarkPicture.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
private void setHdr(HeaderPart headerPart) throws Exception  {

ImagePngPart imagePart = new ImagePngPart(new PartName("/media/background.png"));
imagePart.setBinaryData(image);
Relationship rel = headerPart.addTargetPart(imagePart, AddPartBehaviour.REUSE_EXISTING); // the one image is shared by the 3 header parts

String openXML = "<w:hdr mc:Ignorable=\"w14 wp14\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
           + "<w:p>"
               + "<w:pPr>"
                   + "<w:pStyle w:val=\"Header\"/>"
               +"</w:pPr>"
               + "<w:r>"
                   + "<w:rPr>"
                       + "<w:noProof/>"
                   +"</w:rPr>"
                   + "<w:pict>"
                       + "<v:shapetype coordsize=\"21600,21600\" filled=\"f\" id=\"_x0000_t75\" o:preferrelative=\"t\" o:spt=\"75\" path=\"m@4@5l@4@11@9@11@9@5xe\" stroked=\"f\">"
                           + "<v:stroke joinstyle=\"miter\"/>"
                           + "<v:formulas>"
                               + "<v:f eqn=\"if lineDrawn pixelLineWidth 0\"/>"
                               + "<v:f eqn=\"sum @0 1 0\"/>"
                               + "<v:f eqn=\"sum 0 0 @1\"/>"
                               + "<v:f eqn=\"prod @2 1 2\"/>"
                               + "<v:f eqn=\"prod @3 21600 pixelWidth\"/>"
                               + "<v:f eqn=\"prod @3 21600 pixelHeight\"/>"
                               + "<v:f eqn=\"sum @0 0 1\"/>"
                               + "<v:f eqn=\"prod @6 1 2\"/>"
                               + "<v:f eqn=\"prod @7 21600 pixelWidth\"/>"
                               + "<v:f eqn=\"sum @8 21600 0\"/>"
                               + "<v:f eqn=\"prod @7 21600 pixelHeight\"/>"
                               + "<v:f eqn=\"sum @10 21600 0\"/>"
                           +"</v:formulas>"
                           + "<v:path gradientshapeok=\"t\" o:connecttype=\"rect\" o:extrusionok=\"f\"/>"
                           + "<o:lock aspectratio=\"t\" v:ext=\"edit\"/>"
                       +"</v:shapetype>"
                       + "<v:shape id=\"WordPictureWatermark835936646\" o:allowincell=\"f\" o:spid=\"_x0000_s2050\" style=\"position:absolute;margin-left:0;margin-top:0;width:467.95pt;height:615.75pt;z-index:-251657216;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin\" type=\"#_x0000_t75\">"
                           + "<v:imagedata blacklevel=\"22938f\" gain=\"19661f\" o:title=\"docx4j-logo\" r:id=\"" + rel.getId() + "\"/>"
                       +"</v:shape>"
                   +"</w:pict>"
               +"</w:r>"
           +"</w:p>"
       +"</w:hdr>";

	Hdr hdr = (Hdr)XmlUtils.unmarshalString(openXML);
	
	headerPart.setJaxbElement(hdr);

}