本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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();
}
}
示例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;
}