org.docx4j.wml.ParaRPr Java Examples

The following examples show how to use org.docx4j.wml.ParaRPr. 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: WmlElementUtils.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public static void setParaVanish(PPr ppr, boolean isVanish) {
    ParaRPr parRpr = getParaRPr(ppr);
    BooleanDefaultTrue vanish = parRpr.getVanish();
    if (vanish != null) {
        vanish.setVal(isVanish);
    } else {
        vanish = new BooleanDefaultTrue();
        parRpr.setVanish(vanish);
        vanish.setVal(isVanish);
    }
}
 
Example #2
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setParaVanish(PPr ppr, boolean isVanish) {
    ParaRPr parRpr = getParaRPr(ppr);
    BooleanDefaultTrue vanish = parRpr.getVanish();
    if (vanish != null) {
        vanish.setVal(isVanish);
    } else {
        vanish = new BooleanDefaultTrue();
        parRpr.setVanish(vanish);
        vanish.setVal(isVanish);
    }
}
 
Example #3
Source File: FOPAreaTreeHelper.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
private static P createFillerP() {

    	org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

    	P p = wmlObjectFactory.createP(); 
    	    // Create object for pPr
    	    PPr ppr = wmlObjectFactory.createPPr(); 
    	    p.setPPr(ppr); 
    	        // Create object for rPr
    	        ParaRPr pararpr = wmlObjectFactory.createParaRPr(); 

    	        // Create object for spacing
    	        PPrBase.Spacing pprbasespacing = wmlObjectFactory.createPPrBaseSpacing(); 
    	        ppr.setSpacing(pprbasespacing); 
    	            pprbasespacing.setBefore( BigInteger.valueOf( 800) ); 
    	            pprbasespacing.setAfter( BigInteger.valueOf( 800) ); 
    	    // Create object for r
    	    R r = wmlObjectFactory.createR(); 
    	    p.getContent().add( r); 
    	        // Create object for rPr
    	        RPr rpr = wmlObjectFactory.createRPr(); 
    	        r.setRPr(rpr); 
    	            // Create object for sz
    	            HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure(); 
    	            rpr.setSz(hpsmeasure3); 
    	                hpsmeasure3.setVal( BigInteger.valueOf( 96) ); 

    	        // Create object for t (wrapped in JAXBElement) 
    	        Text text = wmlObjectFactory.createText(); 
    	        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text); 
    	        r.getContent().add( textWrapped); 
    	            text.setValue( "BODY CONTENT"); 

    	return p;
    }
 
Example #4
Source File: WMLPackageUtils.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
/**
 * 在标签处插入内容
 * 
 * @param bm
 * @param wPackage
 * @param object
 * @throws Exception
 */
public static void replaceText(CTBookmark bm,  Object object) throws Exception {
	if (object == null) {
		return;
	}
	// do we have data for this one?
	if (bm.getName() == null)
		return;
	String value = object.toString();
	//Log.info("标签名称:"+bm.getName());
	try {
		// Can't just remove the object from the parent,
		// since in the parent, it may be wrapped in a JAXBElement
		List<Object> theList = null;
		ParaRPr rpr = null;
		if (bm.getParent() instanceof P) {
			PPr pprTemp = ((P) (bm.getParent())).getPPr();
			if (pprTemp == null) {
				rpr = null;
			} else {
				rpr = ((P) (bm.getParent())).getPPr().getRPr();
			}
			theList = ((ContentAccessor) (bm.getParent())).getContent();
		} else {
			return;
		}
		int rangeStart = -1;
		int rangeEnd = -1;
		int i = 0;
		for (Object ox : theList) {
			Object listEntry = XmlUtils.unwrap(ox);
			if (listEntry.equals(bm)) {

				if (((CTBookmark) listEntry).getName() != null) {

					rangeStart = i + 1;

				}
			} else if (listEntry instanceof CTMarkupRange) {
				if (((CTMarkupRange) listEntry).getId().equals(bm.getId())) {
					rangeEnd = i - 1;

					break;
				}
			}
			i++;
		}
		int x = i - 1;
		//if (rangeStart > 0 && x >= rangeStart) {
			// Delete the bookmark range
			for (int j = x; j >= rangeStart; j--) {
				theList.remove(j);
			}
			// now add a run
			org.docx4j.wml.R run = factory.createR();
			org.docx4j.wml.Text t = factory.createText();
			// if (rpr != null)
			// run.setRPr(paraRPr2RPr(rpr));
			t.setValue(value);
			run.getContent().add(t);
			//t.setValue(value);

			theList.add(rangeStart, run);
		//}
	} catch (ClassCastException cce) {
		//Log.error(cce);
	}
}
 
Example #5
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public void createHyperlink(WordprocessingMLPackage wordMLPackage,
		MainDocumentPart t, ObjectFactory factory,P paragraph, String url,
		String value, String fontName, String fontSize,JcEnumeration jcEnumeration) throws Exception {
	org.docx4j.relationships.ObjectFactory reFactory = new org.docx4j.relationships.ObjectFactory();
	org.docx4j.relationships.Relationship rel = reFactory
			.createRelationship();
	rel.setType(Namespaces.HYPERLINK);
	rel.setTarget(url);
	rel.setTargetMode("External");
	t.getRelationshipsPart().addRelationship(rel);
	StringBuffer sb = new StringBuffer();
	// addRelationship sets the rel's @Id
	sb.append("<w:hyperlink r:id=\"");
	sb.append(rel.getId());
	sb.append("\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" ");
	sb.append("xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >");
	sb.append("<w:r><w:rPr><w:rStyle w:val=\"Hyperlink\" />");
	sb.append("<w:rFonts  w:ascii=\"");
	sb.append(fontName);
	sb.append("\"  w:hAnsi=\"");
	sb.append(fontName);
	sb.append("\"  w:eastAsia=\"");
	sb.append(fontName);
	sb.append("\" w:hint=\"eastAsia\"/>");
	sb.append("<w:sz w:val=\"");
	sb.append(fontSize);
	sb.append("\"/><w:szCs w:val=\"");
	sb.append(fontSize);
	sb.append("\"/></w:rPr><w:t>");
	sb.append(value);
	sb.append("</w:t></w:r></w:hyperlink>");

	Hyperlink link = (Hyperlink) XmlUtils.unmarshalString(sb.toString());
	paragraph.getContent().add(link);
	setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0",
			"0", null, null, true, "240", STLineSpacingRule.AUTO);
	PPr ppr = paragraph.getPPr();
	if (ppr == null) {
		ppr = factory.createPPr();
	}
	RFonts fonts = new RFonts();
	fonts.setAscii("微软雅黑");
	fonts.setHAnsi("微软雅黑");
	fonts.setEastAsia("微软雅黑");
	fonts.setHint(STHint.EAST_ASIA);
	ParaRPr rpr = new ParaRPr();
	rpr.setRFonts(fonts);
	ppr.setRPr(rpr);
	paragraph.setPPr(ppr);
}
 
Example #6
Source File: DocxBuilder.java    From TranskribusCore with GNU General Public License v3.0 4 votes vote down vote up
public P createIt() {

		org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

		P p = wmlObjectFactory.createP();
		    // Create object for pPr
		    PPr ppr = wmlObjectFactory.createPPr();
		    p.setPPr(ppr);
		        // Create object for rPr
		        ParaRPr pararpr = wmlObjectFactory.createParaRPr();
		        ppr.setRPr(pararpr);
		            // Create object for u
		            U u = wmlObjectFactory.createU();
		            pararpr.setU(u);
		                u.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
		            // Create object for lang
		            CTLanguage language = wmlObjectFactory.createCTLanguage();
		            pararpr.setLang(language);
		                language.setVal( "en-AU");
		        // Create object for jc
		        Jc jc = wmlObjectFactory.createJc();
		        ppr.setJc(jc);
		            jc.setVal(org.docx4j.wml.JcEnumeration.CENTER);
		    // Create object for r
		    R r = wmlObjectFactory.createR();
		    p.getContent().add( r);
		        // Create object for rPr
		        RPr rpr = wmlObjectFactory.createRPr();
		        r.setRPr(rpr);
		            // Create object for u
		            U u2 = wmlObjectFactory.createU();
		            rpr.setU(u2);
		                u2.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
		            // Create object for lang
		            CTLanguage language2 = wmlObjectFactory.createCTLanguage();
		            rpr.setLang(language2);
		                language2.setVal( "en-AU");
		        // Create object for t (wrapped in JAXBElement)
		        Text text = wmlObjectFactory.createText();
		        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
		        r.getContent().add( textWrapped);
		            text.setValue( "Underlined and centred");
		            
		            

		return p;
		}