java fop,使用ApacheFOP从Java中的XML生成PDF

I am trying to generate on-the-fly PDF reports from Java objects. I have not been able to find many examples of this, so I have been following this example:

The only real difference between this code and my own is that I generate src (line 81 in the example) using JSON conversion and an XMLSerializer.

The problem I run into is using the Transformer. When I do the transform (line 87 of the example), I receive the error message:

(Location of error unknown)org.apache.fop.fo.ValidationException:

First element must be the fo:root formatting object. Found (Namespace

URI: "", Local Name: "html") instead. Please make sure you're

producing a valid XSL-FO document.

Since I don't have visibility into the Transformer, and haven't been able to find the kind of documentation to tell me how it is supposed to work, I don't really know where the transformation is breaking down.

Any experience with this kind of conversion, or understand of whatever it is I'm missing is greatly appreciated.

解决方案

The input of Apache FOP is XSL:FO. The error message is saying that the input is not a valid XSL:FO document because the first (root) element is expected to be "fo:root" but "html" was found. FOP does not read HTML input. I suggest to break down the code in smaller steps and save the intermediate documents to help you identify the problem. The steps are:

JSON object is serialized to XML

XML is transformed using an XSLT to XSL:FO

XSL:FO is transformed using FOP to PDF.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值