本文整理汇总了Java中org.docx4j.fonts.PhysicalFonts.setRegex方法的典型用法代码示例。如果您正苦于以下问题:Java PhysicalFonts.setRegex方法的具体用法?Java PhysicalFonts.setRegex怎么用?Java PhysicalFonts.setRegex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.fonts.PhysicalFonts
的用法示例。
在下文中一共展示了PhysicalFonts.setRegex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的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;
}
示例2: convertToDocXThenPdf
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的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();
}
}
示例3: toPDFDocument
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
@Override
public void toPDFDocument(E data, OutputStream out) throws IOException {
PhysicalFonts.setRegex(null);
prepareDocument();
TemplateContext<E> context = contextFactory.createTemplateContext(this);
context.bind(data);
document.updateDynamicContent(context);
document.writeAsPDF(out);
}
示例4: createTextBoxDocx
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
private static WordprocessingMLPackage createTextBoxDocx(boolean w10WrapEl, String style) throws InvalidFormatException {
// speedup
// String regex = ".*(calibri|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*";
String regex = ".*(calibri|cour|arial).*";
PhysicalFonts.setRegex(regex);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
P p = new P();
mdp.getContent().add(p);
R r = Context.getWmlObjectFactory().createR();
r.getContent().add(
// Absolute position to the right of column produces:
// margin-left:108pt
// mso-position-horizontal:absolute <------------
// mso-position-horizontal-relative:text
// mso-wrap-style:square
// style="position:absolute;margin-left:108pt;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"
createPict(w10WrapEl, style,
createContent("text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content text box content ")));
// Relative position is done in percentages..
// mso-left-percent:600
// mso-position-horizontal-relative:left-margin-area
// mso-width-relative:margin
// style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal-relative:left-margin-area;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-left-percent:600;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"
p.getContent().add( r);
p.getContent().add(addFiller());
return wordMLPackage;
}