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


Java XHTMLImporterImpl类代码示例

本文整理汇总了Java中org.docx4j.convert.in.xhtml.XHTMLImporterImpl的典型用法代码示例。如果您正苦于以下问题:Java XHTMLImporterImpl类的具体用法?Java XHTMLImporterImpl怎么用?Java XHTMLImporterImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XHTMLImporterImpl类属于org.docx4j.convert.in.xhtml包,在下文中一共展示了XHTMLImporterImpl类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; //导入依赖的package包/类
public static WordprocessingMLPackage handle(WordprocessingMLPackage wmlPackage, Document doc,boolean fragment,boolean altChunk) throws IOException, Docx4JException {
	//设置转换模式
	doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);  //转为 xhtml 格式
	
	if(altChunk){
		//Document对象
		MainDocumentPart document = wmlPackage.getMainDocumentPart();
		//获取Jsoup参数
		String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_JSOUP_PARSE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
		//设置转换模式
		doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);  //转为 xhtml 格式
		//创建html导入对象
		//XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
		document.addAltChunk(AltChunkType.Xhtml, (fragment ? doc.body().html() : doc.html()) .getBytes(Charset.forName(charsetName)));
		//document.addAltChunk(type, bytes, attachmentPoint)
		//document.addAltChunk(type, is)
		//document.addAltChunk(type, is, attachmentPoint)
		WordprocessingMLPackage tempPackage = document.convertAltChunks();
		
		//返回处理后的WordprocessingMLPackage对象
		return tempPackage;
	}
	
	//创建html导入对象
	XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wmlPackage);
	//将xhtml转换为wmlPackage可用的对象
	List<Object> list = xhtmlImporter.convert((fragment ? doc.body().html() : doc.html()), doc.baseUri());
	//导入转换后的内容对象
	wmlPackage.getMainDocumentPart().getContent().addAll(list);
	//返回原WordprocessingMLPackage对象
	return wmlPackage;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:33,代码来源:XHTMLImporterUtils.java

示例2: convertToDocx

import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; //导入依赖的package包/类
public void convertToDocx(String markdown, File file) throws Docx4JException, JAXBException {
    WordprocessingMLPackage wordMLPackage;
    wordMLPackage = WordprocessingMLPackage.createPackage();
    NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
    wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
    ndp.unmarshalDefaultNumbering();
    XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
    xHTMLImporter.setHyperlinkStyle("Hyperlink");
    // Must be a properly formatted html doc.. No fragments
    wordMLPackage.getMainDocumentPart().getContent().addAll(
            xHTMLImporter.convert(Utils.wrapWithHtmlDocType(convertToHTML(markdown)),
                    null)
    );
    wordMLPackage.save(file);
}
 
开发者ID:jdesive,项目名称:textmd,代码行数:16,代码来源:MarkdownParser.java

示例3: convertToDocX

import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; //导入依赖的package包/类
public static void convertToDocX(File html, File docx) throws IOException, Docx4JException, JAXBException {

        // Create an empty docx package
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

        NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
        wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
        ndp.unmarshalDefaultNumbering();

        XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
        xHTMLImporter.setHyperlinkStyle("Hyperlink");

        // Convert the XHTML, and add it into the empty docx we made
        wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(html, null));

        wordMLPackage.save(docx);
    }
 
开发者ID:eamonfoy,项目名称:trello-to-markdown,代码行数:18,代码来源:DOCXUtils.java

示例4: convertToDocXThenPdf

import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; //导入依赖的package包/类
public static void convertToDocXThenPdf(File html, File pdf) throws IOException, Docx4JException, JAXBException {

        // Create an empty docx package
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

        NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
        wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
        ndp.unmarshalDefaultNumbering();

        XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
        xHTMLImporter.setHyperlinkStyle("Hyperlink");

        // Convert the XHTML, and add it into the empty docx we made
        wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(html, null));

        //wordMLPackage.save( docx );

        String regex = null;
        PhysicalFonts.setRegex(regex);

        try {
            wordMLPackage.setFontMapper(new IdentityPlusMapper());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // All methods write to an output stream
        OutputStream os = new java.io.FileOutputStream(pdf);


        // Refresh the values of DOCPROPERTY fields
        FieldUpdater updater = new FieldUpdater(wordMLPackage);
        updater.update(true);


        Docx4J.toPDF(wordMLPackage, os);
        System.out.println("Saved: " + pdf.getAbsolutePath());

        // Clean up, so any ObfuscatedFontPart temp files can be deleted
        if (wordMLPackage.getMainDocumentPart().getFontTablePart() != null) {
            wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
        }
    }
 
开发者ID:eamonfoy,项目名称:trello-to-markdown,代码行数:44,代码来源:DOCXUtils.java

示例5: xhtml2word

import org.docx4j.convert.in.xhtml.XHTMLImporterImpl; //导入依赖的package包/类
/**
 * 将 {@link org.jsoup.nodes.Document} 对象转为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage}
 * xhtml to word
 *
 * @param doc
 * @return
 * @throws Exception
 */
protected WordprocessingMLPackage xhtml2word(Document doc) throws Exception {

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.valueOf("A4"), true); //A4纸,//横版:true

    configSimSunFont(wordMLPackage); //配置中文字体

    XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);

    wordMLPackage.getMainDocumentPart().getContent().addAll( //导入 xhtml
            xhtmlImporter.convert(doc.html(), doc.baseUri()));


    return wordMLPackage;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:23,代码来源:HtmlConverter.java


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