当前位置: 首页>>代码示例>>Java>>正文


Java Docx4J.createFOSettings方法代码示例

本文整理汇总了Java中org.docx4j.Docx4J.createFOSettings方法的典型用法代码示例。如果您正苦于以下问题:Java Docx4J.createFOSettings方法的具体用法?Java Docx4J.createFOSettings怎么用?Java Docx4J.createFOSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.docx4j.Docx4J的用法示例。


在下文中一共展示了Docx4J.createFOSettings方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertPDF

import org.docx4j.Docx4J; //导入方法依赖的package包/类
@Override
public File convertPDF(File theFile, String md5UploadedFile) throws PDFConverterException {
	try {
		WordprocessingMLPackage wordMLPckg = Docx4J.load(theFile);
		FOSettings foSettings = Docx4J.createFOSettings();
		foSettings.setWmlPackage(wordMLPckg);
		String outFileName = this.getOutputFileName(md5UploadedFile);
		File outputFile = new File(Config.getString("application.staticFiles"), outFileName);
		FileOutputStream pdfStream = new FileOutputStream(outputFile);
		Docx4J.toFO(foSettings, pdfStream, Docx4J.FLAG_EXPORT_PREFER_XSL);
		pdfStream.close();
		return outputFile;
	} catch (Exception e) {
		log.error("Fail to create PDF in DOC4J Converter", e);
		throw new PDFConverterException("Fail to create PDF in DOC4J Converter", e);
	}
}
 
开发者ID:LeoFCardoso,项目名称:tudoToPDF,代码行数:18,代码来源:Docx4JConverter.java

示例2: convert

import org.docx4j.Docx4J; //导入方法依赖的package包/类
@Override
	public InputStream convert(InputStream fromInputSource, String toMimeType) {
		try {
			// Font regex (optional)
			// Set regex if you want to restrict to some defined subset of fonts
			// Here we have to do this before calling createContent,
			// since that discovers fonts
			String regex = null;
			// Windows:
			// String
			// regex=".*(calibri|camb|cour|arial|symb|times|Times|zapf).*";
			//regex=".*(calibri|camb|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*";
			// Mac
			// String
			// regex=".*(Courier New|Arial|Times New Roman|Comic Sans|Georgia|Impact|Lucida Console|Lucida Sans Unicode|Palatino Linotype|Tahoma|Trebuchet|Verdana|Symbol|Webdings|Wingdings|MS Sans Serif|MS Serif).*";
			PhysicalFonts.setRegex(regex);
			
			WordprocessingMLPackage pkg = WordprocessingMLPackage.load(fromInputSource);
	
			// Refresh the values of DOCPROPERTY fields 
			FieldUpdater updater = new FieldUpdater(pkg);
			updater.update(true);
			
			// FO exporter setup (required)
			// .. the FOSettings object
	    	FOSettings foSettings = Docx4J.createFOSettings();
//			if (false) {
//				foSettings.setFoDumpFile(new java.io.File("/tmp/test.fo"));
//			}
			foSettings.setWmlPackage(pkg);
			
			//ByteArrayOutputStream os = new ByteArrayOutputStream();
			
			String outputfilepath;
			outputfilepath = "/tmp/temp.pdf";
			OutputStream os = new java.io.FileOutputStream(outputfilepath);
	
			// Specify whether PDF export uses XSLT or not to create the FO
			// (XSLT takes longer, but is more complete).
			
			// Don't care what type of exporter you use
			Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
			
			if (pkg.getMainDocumentPart().getFontTablePart()!=null) {
				pkg.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
			}
			
			return new FileInputStream(outputfilepath);
		} catch (Exception e) {
			
		}
		
		return null;
	}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:55,代码来源:WordToPdfRenditionProvider.java

示例3: testTblHeaderOne

import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
	 * "fo:table" content model is: (marker*,table-column*,table-header?,table-footer?,table-body+)
	 * 
	 * so a table with just a table header should have
	 * that converted to table-body row.
	 */
	@Test
	public  void testTblHeaderOne() throws Exception {
		
		String inputfilepath = System.getProperty("user.dir") + "/src/test/resources/tables/tblHeaderTestOne.docx";
		WordprocessingMLPackage wordMLPackage= WordprocessingMLPackage.load(new java.io.File(inputfilepath));	
		
    	FOSettings foSettings = Docx4J.createFOSettings();
		foSettings.setWmlPackage(wordMLPackage);
		
		// want the fo document as the result.
		foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
		
		// exporter writes to an OutputStream.		
		ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    	

		//Don't care what type of exporter you use
//		Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
		//Prefer the exporter, that uses a xsl transformation
		Docx4J.toFO(foSettings, baos, Docx4J.FLAG_EXPORT_PREFER_XSL);

		byte[] bytes = baos.toByteArray();
//		System.out.println(new String(bytes, "UTF-8"));
	
		// Now use XPath to assert it has a table-body
		try {
			org.w3c.dom.Document domDoc = w3cDomDocumentFromByteArray( bytes);
			assertTrue(this.isAbsent(domDoc, "//fo:table-header"));
			assertTrue(this.isPresent(domDoc, "//fo:table-body"));
		} catch (SAXParseException e) {
			
			Assert.fail(e.getMessage());
			Assert.fail(new String(bytes, "UTF-8"));
		}
		
		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:44,代码来源:TblHeaderTest.java

示例4: testTblHeaderTwo

import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
	 * "fo:table" content model is: (marker*,table-column*,table-header?,table-footer?,table-body+)
	 * 
	 * so a table with body rows before header rows should have
	 * those body rows converted to header rows.
	 */
	@Test
	public  void testTblHeaderTwo() throws Exception {
		
		String inputfilepath = System.getProperty("user.dir") + "/src/test/resources/tables/tblHeaderTestTwo.docx";
		WordprocessingMLPackage wordMLPackage= WordprocessingMLPackage.load(new java.io.File(inputfilepath));	
		
    	FOSettings foSettings = Docx4J.createFOSettings();
		foSettings.setWmlPackage(wordMLPackage);
		
		// want the fo document as the result.
		foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
		
		// exporter writes to an OutputStream.		
		ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    	

		//Don't care what type of exporter you use
//		Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
		//Prefer the exporter, that uses a xsl transformation
		Docx4J.toFO(foSettings, baos, Docx4J.FLAG_EXPORT_PREFER_XSL);

		byte[] bytes = baos.toByteArray();
//		System.out.println(new String(bytes, "UTF-8"));
	
		// Now use XPath to assert it has a table-body
		try {
			org.w3c.dom.Document domDoc = w3cDomDocumentFromByteArray( bytes);
			assertTrue(this.isAbsent(domDoc, "//fo:table-body[following-sibling::fo:table-header]"));
			assertTrue(this.isPresent(domDoc, "//fo:table-header[following-sibling::fo:table-body]"));
		} catch (SAXParseException e) {
			
			Assert.fail(e.getMessage());
			Assert.fail(new String(bytes, "UTF-8"));
		}
		
		
		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:45,代码来源:TblHeaderTest.java

示例5: writeAsPDF

import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
 * Writes this document as PDF to a OutputStream and closed the stream in
 * any case.
 * 
 * @param out
 *            - the Outputstream to write the document.
 * @throws IOException
 */
public void writeAsPDF(OutputStream out) throws IOException {

       WordprocessingMLPackage mlPackage = getWordMLPackage();
       
       try {
           FOSettings foSettings = Docx4J.createFOSettings();
           foSettings.setWmlPackage(mlPackage);
           Docx4J.toFO(foSettings, out, Docx4J.FLAG_EXPORT_PREFER_XSL);
       } catch (Exception e) {
       	throw new WteException("Unable to create PDF Document", e);
       } finally {
       	out.close();
       }
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:23,代码来源:Docx4JWordTemplate.java

示例6: writeToPDFWhithFo

import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
 * 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 pdf
 */
public void writeToPDFWhithFo(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
	Assert.notNull(wmlPackage, " wmlPackage is not specified!");
	Assert.notNull(output, " output is not specified!");
       try {
       	
		// Font regex (optional)
		// Set regex if you want to restrict to some defined subset of fonts
		// Here we have to do this before calling createContent,
		// since that discovers fonts
		//String regex = null;
		
		// Refresh the values of DOCPROPERTY fields 
		FieldUpdater updater = new FieldUpdater(wmlPackage);
		updater.update(true);
		
		// .. example of mapping font Times New Roman which doesn't have certain Arabic glyphs
		// eg Glyph "ي" (0x64a, afii57450) not available in font "TimesNewRomanPS-ItalicMT".
		// eg Glyph "ج" (0x62c, afii57420) not available in font "TimesNewRomanPS-ItalicMT".
		// to a font which does
		PhysicalFonts.get("Arial Unicode MS"); 

		// FO exporter setup (required)
		// .. the FOSettings object
	    FOSettings foSettings = Docx4J.createFOSettings();
	    
		foSettings.setWmlPackage(wmlPackage);
        foSettings.setApacheFopMime("application/pdf");
            
		// Document format: 
		// The default implementation of the FORenderer that uses Apache Fop will output
		// a PDF document if nothing is passed via 
		// foSettings.setApacheFopMime(apacheFopMime)
		// apacheFopMime can be any of the output formats defined in org.apache.fop.apps.MimeConstants eg org.apache.fop.apps.MimeConstants.MIME_FOP_IF or
		// FOSettings.INTERNAL_FO_MIME if you want the fo document as the result.
		//foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
		
		// Specify whether PDF export uses XSLT or not to create the FO
		// (XSLT takes longer, but is more complete).
		
		// Don't care what type of exporter you use
		Docx4J.toFO(foSettings, output, Docx4J.FLAG_EXPORT_PREFER_XSL);
		
		// Prefer the exporter, that uses a xsl transformation
		// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
		
		// Prefer the exporter, that doesn't use a xsl transformation (= uses a visitor)
		// faster, but not yet at feature parity
		// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
		   
		// Clean up, so any ObfuscatedFontPart temp files can be deleted 
		// if (wordMLPackage.getMainDocumentPart().getFontTablePart()!=null) {
		// 	wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
		// } 
		// This would also do it, via finalize() methods
		updater = null;
		foSettings = null;
		wmlPackage = null;
	} finally{
		IOUtils.closeQuietly(output);
       }
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:65,代码来源:WordprocessingMLPackageWriter.java

示例7: getAreaTreeViaFOP

import org.docx4j.Docx4J; //导入方法依赖的package包/类
static org.w3c.dom.Document getAreaTreeViaFOP(WordprocessingMLPackage hfPkg, boolean useXSLT) throws Docx4JException, ParserConfigurationException, SAXException, IOException  {

    	  // Currently FOP dependent!  But an Antenna House version ought to be feasible.
    	
        FOSettings foSettings = Docx4J.createFOSettings();
        foSettings.setWmlPackage(hfPkg);
        foSettings.setApacheFopMime(MimeConstants.MIME_FOP_AREA_TREE);
        
        foSettings.setLayoutMasterSetCalculationInProgress(true); // avoid recursion
        
//        foSettings.getFeatures().add(ConversionFeatures.PP_PDF_APACHEFOP_DISABLE_PAGEBREAK_LIST_ITEM); // in 3.0.1, this is off by default
        
        // Since hfPkg is already a clone, we don't need PP_COMMON_DEEP_COPY
        // Plus it invokes setFontMapper, which does processEmbeddings again, and those fonts aren't much use to us here
        foSettings.getFeatures().remove(ConversionFeatures.PP_COMMON_DEEP_COPY);
        
        if (log.isDebugEnabled()) {
        	foSettings.setFoDumpFile(new java.io.File(System.getProperty("user.dir") + "/hf.fo"));
        }

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        
        if (useXSLT) {
        	Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
        } else {
        	Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);        	
        }
        
        InputStream is = new ByteArrayInputStream(os.toByteArray());
		DocumentBuilder builder = XmlUtils.getNewDocumentBuilder();
		return builder.parse(is);

    }
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:34,代码来源:FOPAreaTreeHelper.java

示例8: testTblIndentOnCentredTable

import org.docx4j.Docx4J; //导入方法依赖的package包/类
@Test
	@Ignore
	public  void testTblIndentOnCentredTable() throws Exception {
		
		boolean save = true;
		
		WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
		wordMLPackage.getMainDocumentPart().setJaxbElement(
				(Document)XmlUtils.unmarshalString(table1XML));		
		
		
    	FOSettings foSettings = Docx4J.createFOSettings();
		foSettings.setWmlPackage(wordMLPackage);
		
		OutputStream os = null;
		if (save) {
			
			os = new FileOutputStream(new File(System.getProperty("user.dir") + "/OUT_testTblIndentOnCentredTable.pdf"));
			wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_testTblIndentOnCentredTable.docx"));
		} else {
			// want the fo document as the result.
			foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
			
			// exporter writes to an OutputStream.		
			os = new ByteArrayOutputStream(); 
		}
		
    	

		//Don't care what type of exporter you use
//		Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
		//Prefer the exporter, that uses a xsl transformation
		Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

		if (save) {
			
		} else {
			byte[] bytes = ((ByteArrayOutputStream)os).toByteArray();
	//		System.out.println(new String(bytes, "UTF-8"));
		
			// Now use XPath to assert it has a table-body
			org.w3c.dom.Document domDoc = w3cDomDocumentFromByteArray( bytes);
			
			assertTrue(this.isAbsent(domDoc, "//fo:table-header"));
			assertTrue(this.isPresent(domDoc, "//fo:table-body"));
		}
		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:49,代码来源:TableIndentTest.java

示例9: testTblIndentInheritance

import org.docx4j.Docx4J; //导入方法依赖的package包/类
public  void testTblIndentInheritance() throws Exception {
		
		boolean save = true;
		
		WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
		wordMLPackage.getMainDocumentPart().setJaxbElement(
				(Document)XmlUtils.unmarshalString(table1XML));		
		
		
    	FOSettings foSettings = Docx4J.createFOSettings();
		foSettings.setWmlPackage(wordMLPackage);
		
		OutputStream os = null;
		if (save) {
			
			os = new FileOutputStream(new File(System.getProperty("user.dir") + "/OUT_testTblIndentInheritance.pdf"));
			wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_testTblIndentInheritance.docx"));
		} else {
			// want the fo document as the result.
			foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
			
			// exporter writes to an OutputStream.		
			os = new ByteArrayOutputStream(); 
		}
		
    	

		//Don't care what type of exporter you use
//		Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
		//Prefer the exporter, that uses a xsl transformation
		Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

		if (save) {
			
		} else {
			byte[] bytes = ((ByteArrayOutputStream)os).toByteArray();
			System.out.println(new String(bytes, "UTF-8"));
		
			// Now use XPath to assert it has a table-body
			org.w3c.dom.Document domDoc = w3cDomDocumentFromByteArray( bytes);
			
			assertTrue(this.isAbsent(domDoc, "//fo:table-header"));
			assertTrue(this.isPresent(domDoc, "//fo:table-body"));
		}
		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:47,代码来源:TableIndentInheritance.java


注:本文中的org.docx4j.Docx4J.createFOSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。