org.docx4j.openpackaging.packages.OpcPackage Java Examples

The following examples show how to use org.docx4j.openpackaging.packages.OpcPackage. 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: SessionStyleHandler.java    From docx-html-editor with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
	public Element createStyleElement(OpcPackage opcPackage, Document document,
			String styleDefinition) {

		
		if ((styleDefinition != null) && (styleDefinition.length() > 0)) {
    		session.setAttribute("css", styleDefinition);
//    		System.out.println(styleDefinition);
    		
    		//<link rel="stylesheet" type="text/css" href="/docx4j-web-editor-1.0.0-SNAPSHOT/services/css/docx.css" />
    		
    		
//			Element ret = document.createElement("link");
//			ret.setAttribute("rel", "stylesheet");
//			ret.setAttribute("type", "text/css");
//			ret.setAttribute("href", Editor.getContextPath() + "/services/css/docx.css");
//    		return ret;
    		
		} else {
    		System.out.println("styleDefinition was null or empty!");			
		}
		return null;
	}
 
Example #2
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @Description:加载带密码WordprocessingMLPackage
 */
public static WordprocessingMLPackage loadWordprocessingMLPackageWithPwd(String filePath, String password)
        throws Exception {
    OpcPackage opcPackage = WordprocessingMLPackage.load(new java.io.File(filePath), password);
    WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) opcPackage;
    return wordMLPackage;
}
 
Example #3
Source File: OutputConversionHTMLScriptElementHandler.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
@Override
public Element createScriptElement(OpcPackage opcPackage, Document document, String scriptDefinition) {
	Element ret = null;
	if ((scriptDefinition != null) && (scriptDefinition.length() > 0)) {
		ret = document.createElement("script");
		ret.setAttribute("type", "text/javascript");
		ret.appendChild(document.createComment(scriptDefinition));
	}
	return ret;
}
 
Example #4
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @Description:加载带密码WordprocessingMLPackage
 */
public WordprocessingMLPackage loadWordprocessingMLPackageWithPwd(
        String filePath, String password) throws Exception {
    OpcPackage opcPackage = WordprocessingMLPackage.load(new java.io.File(
            filePath), password);
    WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) opcPackage;
    return wordMLPackage;
}
 
Example #5
Source File: OutputConversionHyperlinkHandler.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
@Override
public void handleHyperlink(Model hyperlinkModel, OpcPackage opcPackage, Part currentPart) throws Docx4JException {
	//do nothing
}
 
Example #6
Source File: XsltFOFunctions.java    From docx4j-export-FO with Apache License 2.0 4 votes vote down vote up
private static void createFoAttributes(OpcPackage opcPackage, PPr pPr, Element foBlockElement, boolean inList, boolean ignoreBorders){
		
    	List<Property> properties = PropertyFactory.createProperties(opcPackage, pPr);
    	
    	for( Property p :  properties ) {
			if (p!=null) {
				
				if (ignoreBorders &&
						((p instanceof PBorderTop)
								|| (p instanceof PBorderBottom))) {
					continue;
				}
								
				if (inList && !(p instanceof Indent) ) { 
					// Don't set start-indent in 
					// fo:list-item-body/fo:block.
					// This has to be handled above using something like 
					//  <fo:list-block provisional-distance-between-starts="0.5in" start-indent="2in">
					p.setXslFO(foBlockElement);
				} else if (!inList) {
					p.setXslFO(foBlockElement);
				}
			}
    	}
    	
    	if (pPr==null) return;
		
    	// Special case, since bidi is translated to align right
    	// Handle interaction between w:pPr/w:bidi and w:pPr/w:jc/@w:val='right'
    	if (pPr.getBidi()!=null && pPr.getBidi().isVal()) {
    		
    		if (pPr.getJc()!=null) {
    			if (pPr.getJc().getVal().equals(JcEnumeration.RIGHT)) {
    				// set it to left!
    				foBlockElement.setAttribute(Justification.FO_NAME,  "left");
    			} else if (pPr.getJc().getVal().equals(JcEnumeration.LEFT)) {
    				// set it to right!
    				foBlockElement.setAttribute(Justification.FO_NAME,  "right");
    			}
    		}
    	}
    	
    	// Table of contents dot leader needs text-align-last="justify"
    	// Are we in a TOC?
    	if (pPr.getTabs()!=null
    			
    			// PStyle is not included in our effective pPr!
//    			&& pPr.getPStyle()!=null 
//    			&& pPr.getPStyle().getVal()!=null
//    			&& pPr.getPStyle().getVal().startsWith("TOC")  
    			) {
    		
    		CTTabStop tabStop = pPr.getTabs().getTab().get(0);
    		if (tabStop!=null
    				//&& tabStop.getLeader().equals(STTabTlc.DOT)
    				&& tabStop.getVal().equals(STTabJc.RIGHT) ) {
    			
    			foBlockElement.setAttribute("text-align-last",  "justify");
    		}
    	}
    	
	}
 
Example #7
Source File: XsltFOFunctions.java    From docx4j-export-FO with Apache License 2.0 3 votes vote down vote up
private static void createFoAttributes(OpcPackage opcPackage,
		RPr rPr, Element foInlineElement){

   	List<Property> properties = PropertyFactory.createProperties(opcPackage, rPr);
   	
   	for( Property p :  properties ) {
   		p.setXslFO(foInlineElement);
   	}
	
}