开发者

Generating pdf document from a json object

开发者 https://www.devze.com 2023-03-07 06:59 出处:网络
I have a json object that is actually an arraylist of objects previously converted to json. What I\'d like to do is to create a table like structure in my pdf document, grabing several object fields

I have a json object that is actually an arraylist of objects previously converted to json.

What I'd like to do is to create a table like structure in my pdf document, grabing several object fields and mapping th开发者_JS百科em to a column found in the table in pdf.

What is the quickest way I can do this?Or which libraries are common for java developers to render pdf.

My project is a web project, using spring mvc. I wonder if there is a way to generate pdf using @ResponseBody, obviously not, I've found few interesting libraries among those are jasper and fop. But they all seem to use xml, is there a way to convert POJO to entries in pdf?

When I was using php, many developers used fpdf library it was pretty straight forward

I found this great tutorial :

http://www.mkyong.com/spring-mvc/spring-mvc-export-data-to-pdf-file-via-abstractpdfview/

But I'm having problems with rotating all my pages to landscape.

I tried :

document.setPageSize(PageSize.LETTER.rotate());

But it only rotates the last page.


You can convert your JSON to XML using XML class from json.org and then use some example from Apache FOP to construct XSL transformation that will produce you a PDF.


Override the protected method newDocument;

protected Document newDocument() {
    final float margin = 30.0f;
    return new Document(PageSize.A4.rotate(), margin, margin, margin,
            margin);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消