我有以下模板来生成一个定义的表:
<xsl:template name="CreateTable">
<fo:block>
<fo:table border-style="solid" table-layout="fixed">
<fo:table-body>
<fo:table-row>
<xsl:for-each select="Table/Head/Cell">
<fo:table-cell border-style="solid">
<fo:block><xsl:value-of select="." /></fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
<xsl:for-each select="Table/Row">
<fo:table-row>
<xsl:for-each select="Cell">
<fo:table-cell border-style="solid">
<fo:block><xsl:value-of select="."/></fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
<fo:block margin-top="10pt"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
现在我想将第一行中的文本旋转90度,以便从下往上阅读.
我想出的最佳解决方案是:
设置reference-orientation="0"上<fo:table>:
<fo:table border-style="solid" table-layout="fixed" reference-orientation="0">
Run Code Online (Sandbox Code Playgroud)包围<fo:block>...</fo:block>内<fo:table-cell>具有<fo:block-container>被旋转90度:
<fo:table-cell border-style="solid">
<fo:block-container reference-orientation="90">
<fo:block><xsl:value-of select="." /></fo:block>
</fo:block-container>
</fo:table-cell>
Run Code Online (Sandbox Code Playgroud)文本是旋转的,但第一行的高度实际为0,文本显示在表格上方,覆盖了前一个文本:
为第一行的单元格定义特定高度时,文本仍在表格之前,而不在第一行内:
如何在第一行的单元格中定位文本,并根据行中最长的文本自动计算行的高度?
我正在使用Microsoft Word 2007.我想将Word文档转换为XSL-FO.网上有一些提示,但仅适用于RenderX.Apache FOP有这样的工具吗?
这是我的第一个问题,我希望我做得对.抱歉我的英语不好提前:)
我正在使用JSF 2.0(Eclipse IDE),我正在尝试使用Apache FOP 1.0生成一些PDF文件.
我能够使用Apache Fop站点上的说明制作简单的PDF文件,但我无法从我的应用程序文件夹中插入任何图像.我的文件夹结构是这样的:在我的应用程序WebContent中我有(除此之外)pdf_transform/xslt/transformFile.xsl和pdf_transform/xslt/logo.jpg
在transformFile.xsl我有
<fo:block><fo:external-graphic src="url('logo.jpg')"/></fo:block>
Run Code Online (Sandbox Code Playgroud)
但是当我在我的servlet中clik'showPDF'按钮时,我得到没有图像的PDF文件(其他一切都在那里),并在控制台中显示以下消息:
严重:从URI解析返回的Source不包含URI的InputStream:logo.jpg 2010年11月18日下午5:16:49 org.apache.fop.events.LoggingEventListener processEvent SEVERE:找不到图像.URI:logo.jpg.(没有上下文信息)
我尝试使用'logo.jpg'而不是url('logo.jpg'),将图像放在WebContent文件夹内的各个位置并使用不同的导航("./ logo.jpg"),但它没有用.
如果我设置绝对路径(例如"d:/fop/images/logo.jpg"),它工作正常,但我需要在我的应用程序中恢复.
在搜索时,我发现这与fopFactory.setURIResolver()和/或userAgent.setBaseURL()有关.尝试过这个,但没有成功.
我是JSF和FOP的新手,这种形象的情况一直困扰着我.有人可以帮我解决这个问题吗,或者至少指导一下"如何配置相对路径使用FOP"的教程?
编辑:我不希望任何绝对路径和应用程序应独立于其在计算机上的位置工作(可发布).我的搜索告诉我它与配置FOP有关,但我不知道该怎么做:)
提前致谢.
PS这是一种被称为显示PDF的方法:
public void printExchangeRateList(ActionEvent event) {
BufferedOutputStream output = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
String path = externalContext.getRealPath("/");
try {
response.reset();
response.setHeader("Content-Type", "application/pdf");
output = new BufferedOutputStream(response.getOutputStream(), 10240);
File xsltfile = new File(path+"/pdf_transform/xslt/transformFile.xsl");
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
try {
Fop fop …Run Code Online (Sandbox Code Playgroud) 我最近使用FOP编译了一个Android应用程序,因为我想将一些XML转换为PDF文件.但是我不认为FOP JAR文件不适用于Android.有没有适用于Android的FOP版本?或者我可以在我的应用程序中使用的任何其他XML到PDF转换器,而不是连接到Internet上的FOP启用的服务器?
我尝试过包含fop.jar和xmlgraphics.jar,但即使添加到我的项目中,调用也会FopFactory.newInstance()失败.
这是我调用FOP的按钮点击的代码片段:
// Add button listener
btnCreatePDF.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
FopFactory fopFactory = FopFactory.newInstance();
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("/sdcard/test.pdf")));
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(new File("/sdcard/test.fo"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
out.close();
}
});Run Code Online (Sandbox Code Playgroud)
编译器也给了我一堆Dxwarning: Ignoring InnerClasses attribute...错误.单击按钮创建PDF时出现错误:
02-22 14:16:23.641: WARN/System.err(5590): java.lang.UnsupportedOperationException: Don't know how to handle "application/pdf" as an output format. Neither …Run Code Online (Sandbox Code Playgroud) 在找到"keep-together"属性,并且需要不在一行内部分页时keep-together="always",我在xslt中的每个table-row元素上添加了.有没有更好的方法来达到同样的效果?看起来有点hacky.(ps.如果没有人提供更好的答案,我会接受"否"作为答案,前提是提供了某种解释.)
我正在努力使用我的xsl:fo(Apache Fop 1.1).我正在尝试使用内嵌图像和内联文本元素生成一个块,其中可能包含换行符.
<fo:block>
<fo:inline>First Line Second Line, Image: </fo:inline>
<fo:inline>
<fo:external-graphic scaling="non-uniform" content-height="scale-to-fit" content-width="4mm" height="4mm" src="data:image;base64,iVBORw0KGgoAAAANSUhEUgAAAGcAAABfCAIAAAB6Ck5uAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA0SURBVHhe7cGBAAAAAMOg+VNf4QBVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHCoAXMKAAFau+l4AAAAAElFTkSuQmCC"/>
</fo:inline>
<fo:inline> some more Text on Line 2 3rd Line</fo:inline>
</fo:block>
Run Code Online (Sandbox Code Playgroud)
我希望输出会是
FirstLine
SecondLine, Image: || some more Text on Line 2
3rd Line
Run Code Online (Sandbox Code Playgroud)
我得到的是:
FirstLine SecondLine, Image: || some more Text on Line 2 3rd Line
Run Code Online (Sandbox Code Playgroud)
我已经玩了一段时间,在fo:block元素和/或fo:inline元素上有以下属性,给出了奇怪或意外的结果.
white-space-collapse="false"
white-space-treatment="preserve"
linefeed-treatment="preserve"
Run Code Online (Sandbox Code Playgroud)
有什么建议?
编辑1:将内联元素更改为这样的块
<fo:block white-space-treatment="ignore">
<fo:block white-space="pre">First Line
Second Line, Image: </fo:block>
<fo:block>
<fo:external-graphic scaling="non-uniform" content-height="scale-to-fit" content-width="4mm" height="4mm" src="data:image;base64,iVBORw0KGgoAAAANSUhEUgAAAGcAAABfCAIAAAB6Ck5uAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA0SURBVHhe7cGBAAAAAMOg+VNf4QBVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHCoAXMKAAFau+l4AAAAAElFTkSuQmCC"/>
</fo:block>
<fo:block white-space="pre"> some more Text on …Run Code Online (Sandbox Code Playgroud) 我正在使用 Apache FOP(v 2.3 和测试 v 2.5)。我最近从 Oracle JDK 8 升级到 Oracle JDK 11。我在 Oracle Linux(RedHat 衍生版本)上使用 JBoss EAP 7.2。使用 JDK 8 时一切正常,但只是升级到 JDK 11 就导致我的 XML -> PDF 和 XML -> PNG 的 FOP XSLT 创建以下堆栈跟踪(FOP 版本并不重要,因为会产生相同的错误)。
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
Run Code Online (Sandbox Code Playgroud)
我的字体是 Google/RedHat 的 LiberationSans,我已将它们放在文件系统上并在名为 LiberationSans.xconf 的文件中进行配置。我已确保这些文件是全局可读的 (775),并且由运行 JBoss 实例的用户拥有。
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
Run Code Online (Sandbox Code Playgroud)
在我的本地 Windows 计算机上一切正常,但我的部署是通过 Eclipse/JBoss 插件进行的,因此可能存在一些问题。Linux 服务器上的部署是通过 jboss-cli 进行的。
如果我可以提供任何其他可能有帮助的信息,请告诉我。如果我们必须放弃 FOP,我希望这是最后的手段。
我正在尝试使用FOP生成PDF文档.pdf生成代码保存在servlet中,xsl位于WebContent文件夹中的特定文件夹中.
如何通过提供相对路径来访问此xsl文件?它仅在我在File对象中提供完整路径时才有效.
我需要动态生成xml内容.如何将此动态生成的xml作为源而不是File对象?
请提供您的建议.
fonts我的应用程序的 JAR 目录中有一个 TTF 字体。
myapp.jar /
fop /
config.xml
font.ttf
Run Code Online (Sandbox Code Playgroud)
我以这种方式创建我的 FOP:
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setStrictValidation(false);
fopFactory.setUserConfig(getClasspathFile("/fop/config.xml"));
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
...
Run Code Online (Sandbox Code Playgroud)
如何配置config.xml嵌入font.ttf到我正在渲染的 PDF 文件中?
我目前正在使用该Apache FOP库生成PDF文件.我希望这些PDF不受复制粘贴的影响,因此人们必须使用实际的OCR库(或手动输入)来获取PDF上的信息.
FOP显然提供了一些安全性,然后meta-data在PDF上添加,以防止打印或复制等事情,但这似乎无法正常工作(启用打印时无法禁用复制粘贴等).
对我来说似乎很简单的可能性基本上是以某种方式将PDF上的所有文本转换为图像,但我无法找到有关此事的任何信息.
显然我不关心PDF是否可搜索.我只是想阻止人们复制粘贴,而他们仍然可以打印它.
我目前的FOP代码:
private static FopFactory fopFactory;
private static FopFactory initializeFactory() throws IOException,
SAXException {
if (fopFactory == null) {
File f = new File(SettingUtil.getSetting(LetterGeneratorSettings.FOP_CONFIG_LOCATION));
fopFactory = FopFactory.newInstance(f);
}
return fopFactory;
}
public static File generatePDFFromXML(File fopTemplate, File xmlSource,
File resultFileLocation) throws IOException {
try {
initializeFactory();
URL url = fopTemplate.toURI().toURL();
// creation of transform source
StreamSource transformSource = new StreamSource(url.openStream());
// create an instance of fop factory
// a user …Run Code Online (Sandbox Code Playgroud) apache-fop ×10
xsl-fo ×4
java ×3
pdf ×2
android ×1
java-11 ×1
jboss-eap-7 ×1
jsf-2 ×1
ms-word ×1
oraclelinux ×1
servlets ×1
xslt ×1