java - Apache FOP 设置动态 DPI
问题描述
我想 Apache FOP 2.3 将 XML+XSL 转换为 PNG 图像。我希望能够为每个图像动态设置 DPI。下面,我有一个工作示例,我通过 FOUserAgent 设置 dpi。我的问题是:这是通过 Apache FOP 设置 DPI 的传统方式吗?或者它必须以不同的方式设置?
public OutputStream transformXSL2Image(String xmlString, String xslString, String docsPerPage, String defaultTransformer, String startPackCount, String totalPackCount, int dpi) throws Exception {
File file = new File("out.png");
OutputStream fileOut = new BufferedOutputStream(new FileOutputStream(file));
// Set some FOP settings
FOUserAgent userAgent = getFopFactory().newFOUserAgent();
userAgent.setProducer("Apache FOP");
userAgent.setCreator("API");
// This is how I set DPI
userAgent.setTargetResolution(dpi);
Fop fop = getFopFactory().newFop(MimeConstants.MIME_PNG, userAgent, fileOut);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslString);
Result result = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlString, result);
return fileOut;
}
private FopFactory getFopFactory() {
if (fopFactory == null) {
try {
fopFactory = FopFactory.newInstance(new File("resources/fop_config.xml").toURI());
} catch (Exception ex) {
throw ex;
}
}
return factory;
}
谢谢你的帮助!
解决方案
推荐阅读
- powershell - AD中的用户创建
- swift - 可选属性导致 Swift 协议崩溃
- python - 正则表达式中的 Python 可选组
- python - Python selenium - 我如何能够点击屏幕上具有特定值的所有按钮
- sql - JOIN 条件下的 SQL 查询
- python - Python numpy:用特定范围内的新值替换值的for循环向量
- flutter - 我已删除 Pub\Cache\hosted\pub.dartlang.org 文件夹以更新颤振包,但在颤振包中显示错误获取
- python - 集成终端停止在 Visual Studio Code 中显示文本
- python-3.x - 即使安装 ffmpeg 也找不到 FFserver 命令
- javascript - 如何从 Map.keys() 中获取排序数组