本文整理匯總了Java中org.apache.fop.apps.FopFactory.setUserConfig方法的典型用法代碼示例。如果您正苦於以下問題:Java FopFactory.setUserConfig方法的具體用法?Java FopFactory.setUserConfig怎麽用?Java FopFactory.setUserConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.fop.apps.FopFactory
的用法示例。
在下文中一共展示了FopFactory.setUserConfig方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initFopFactoryFromJar
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
public FopFactory initFopFactoryFromJar() throws IOException, SAXException, ConfigurationException {
FopFactory fopFactory = FopFactory.newInstance();
FOURIResolver uriResolver = (FOURIResolver) fopFactory.getURIResolver();
if (context != null) {
uriResolver.setCustomURIResolver(new CustomResolver(context));
} else {
uriResolver.setCustomURIResolver(new CustomResolver());
}
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration cfg = builder.build(getClass().getResourceAsStream("fop-pdf-thai.xml"));
fopFactory.setUserConfig(cfg);
return fopFactory;
}
示例2: readInput
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
protected void readInput(PipelineContext context, ProcessorInput input, Config config, OutputStream outputStream) {
try {
// Setup FOP to output PDF
final FopFactory fopFactory = FopFactory.newInstance();
final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
final URL configFileUrl = this.getClass().getClassLoader().getResource("fop-userconfig.xml");
if (configFileUrl == null) {
logger.warn("FOP config file not found. Please put a fop-userconfig.xml file in your classpath for proper display of UTF-8 characters.");
} else {
final File userConfigXml = new File(configFileUrl.getFile());
fopFactory.setUserConfig(userConfigXml);
}
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outputStream);
// Send data to FOP
readInputAsSAX(context, INPUT_DATA, new ForwardingXMLReceiver(fop.getDefaultHandler()));
} catch (Exception e) {
throw new OXFException(e);
}
}
示例3: givenAConfigurationFile
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
private void givenAConfigurationFile(String filename, EventListener eventListener)
throws Exception {
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(new File("test/resources/org/apache/fop/render/pdf/"
+ filename + ".xconf"));
foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.getEventBroadcaster().addEventListener(eventListener);
}
示例4: generatePDF
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
/**
* Takes a DOM structure and renders a PDF
*
* @param doc
* DOM structure
* @param xslFileName
* XSL file to use to translate the DOM document to FOP
*/
@SuppressWarnings("unchecked")
protected void generatePDF(Document doc, OutputStream streamOut)
{
String xslFileName = "participants-all-attrs.xsl";
Locale currentLocale = rb.getLocale();
if (currentLocale!=null){
String fullLocale = currentLocale.toString();
xslFileName = "participants-all-attrs_" + fullLocale + ".xsl";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
xslFileName = "participants-all-attrs_" + currentLocale.getCountry() + ".xsl";
inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
//We use the default file
xslFileName = "participants-all-attrs.xsl";
}
}
IOUtils.closeQuietly(inputStream);
}
String configFileName = "userconfig.xml";
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
InputStream configInputStream = null;
try
{
configInputStream = getClass().getClassLoader().getResourceAsStream(configFileName);
Configuration cfg = cfgBuilder.build(configInputStream);
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(cfg);
fopFactory.setStrictValidation(false);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
if (!StringUtils.isEmpty(ServerConfigurationService.getString("pdf.default.font"))) {
// this allows font substitution to support i18n chars in PDFs - SAK-21909
FontQualifier fromQualifier = new FontQualifier();
fromQualifier.setFontFamily("DEFAULT_FONT");
FontQualifier toQualifier = new FontQualifier();
toQualifier.setFontFamily(ServerConfigurationService.getString("pdf.default.font", "Helvetica"));
FontSubstitutions result = new FontSubstitutions();
result.add(new FontSubstitution(fromQualifier, toQualifier));
fopFactory.getFontManager().setFontSubstitutions(result);
}
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, streamOut);
InputStream in = getClass().getClassLoader().getResourceAsStream(xslFileName);
Transformer transformer = transformerFactory.newTransformer(new StreamSource(in));
transformer.setParameter("titleName", rb.getString("sitegen.siteinfolist.title.name"));
transformer.setParameter("titleSection", rb.getString("sitegen.siteinfolist.title.section"));
transformer.setParameter("titleId", rb.getString("sitegen.siteinfolist.title.id"));
transformer.setParameter("titleCredit", rb.getString("sitegen.siteinfolist.title.credit"));
transformer.setParameter("titleRole", rb.getString("sitegen.siteinfolist.title.role"));
transformer.setParameter("titleStatus", rb.getString("sitegen.siteinfolist.title.status"));
Source src = new DOMSource(doc);
transformer.transform(src, new SAXResult(fop.getDefaultHandler()));
}
catch (Exception e)
{
log.warn(this+".generatePDF(): " + e);
return;
}
finally
{
IOUtils.closeQuietly(configInputStream);
}
}
示例5: exportSearchPdf
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
public void exportSearchPdf(OutputStream outputStream) throws FOPException, IOException, TransformerException {
setupSearchForm();
loadObjects();
setupTableForm4ExportAll(Mode.VIEW);
FopFactory fopFactory = FopFactory.newInstance();
// hongliangpan add
try {
String fopConfig = "fop.xml";
String filePath = CrudAction4ItsProject.class.getClassLoader().getResource(fopConfig).getPath();
fopFactory.setUserConfig(filePath);
// String fonts = "/fonts"; 的上級目錄
fopFactory.setFontBaseURL(new File(filePath).getParent());
} catch (SAXException e) {
logger.error(e.getMessage(), e);
}
InputStream xsltStream = null;
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, outputStream);
xsltStream = getSearchPdfXsltStream();
// Setup XSLT
TransformerFactory Factory = TransformerFactory.newInstance();
Transformer transformer = Factory.newTransformer(new StreamSource(xsltStream));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Reader reader = composeXmlSearch();
Source src = new StreamSource(reader);
// Resulting SAX events (the generated FO) must be piped through to
// FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
reader.close();
outputStream.flush();
} finally {
IOUtils.closeQuietly(xsltStream);
}
}
示例6: createFopFactory
import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
/** Create a FOP factory and configure it, if we don't already have one. */
private FopFactory createFopFactory(XPathContext context)
throws ConfigurationException, SAXException, IOException, XPathException
{
// See if any font directories were specified.
String fontDirs = "";
if (attribs.containsKey("fontDirs"))
fontDirs = attribs.get("fontDirs").evaluateAsString(context);
// If we've already created a factory with this set of font directories,
// don't re-create (it's expensive.)
//
if (fopFactories.containsKey(fontDirs))
return fopFactories.get(fontDirs);
// Gotta make a new one.
FopFactory factory = FopFactory.newInstance();
if (fontDirs.length() > 0)
{
// The only way I've figured out to put font search directories into the
// factory is to feed in an XML config file. So construct one.
//
StringBuilder buf = new StringBuilder();
buf.append("<?xml version=\"1.0\"?>" +
"<fop version=\"1.0\">" +
" <renderers>" +
" <renderer mime=\"application/pdf\">" +
" <fonts>");
for (String dir : fontDirs.split(";"))
buf.append(" <directory>" + dir + "</directory>");
buf.append(" </fonts>" +
" </renderer>" +
" </renderers>" +
"</fop>");
// Jump through hoops to make the XML into an InputStream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos);
osw.write(buf.toString());
osw.flush();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
// Build the configuration and stick it into the factory.
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration config = cfgBuilder.build(bis);
factory.setUserConfig(config);
}
// Cache this factory so we don't have to create it again (they're expensive.)
fopFactories.put(fontDirs, factory);
return factory;
}