In my application the user can configure their own table layouts to display the data on the screen, by choosing which colums in which order are to be shown. Now I want to give my users the possibility to export these tables to PDF. The tables should fill the page width completely and the columns should adjust their size depending on the content in the table, like e.g. HTML tables do.
Can you recomment a library or toolchain for this?
I checked Apache FOP, but their fo:tables do not support automatic table layout. Creating a Jasper Report dynamically also doesn't seem to fit, because I have to specify the exact column width there. So, does anyone have an idea how to achive this?
Open Source solutions with commercially friendly licenses like Apache or LGPL preferred.
ANSWER: There are no current tools that allow what I hoped for, so I mark this question as resolved.
iText is probably what you are looking for http://itextpdf.com/. Version 2.1.7 is free to use under the GPL lisence, for more info see this question What is latest version of itext that is not AGPL?. It will work for you need, I would recommend using their code samples on their web page. Most are applicable to version 2.1.7 although it is currently on version 5.
I would recommend you take a look at Flying Saucer. It is an open source project that uses iText PDF as its core rendering engine but it allows you to define very dynamic xhtml files as your rendering medium.
Benefits of using FS+iText using iText by itself
Allows for a much faster dev cycle for changes or new products
Very easy to add in consistent and complex styles using a language built exactly for it (HTML + CSS)
You can use the same HTML code to render your PDF as you use to view it online (if using web application)
Can render graphics using java.awt.Graphics class onto the PDF, meaning you can integrate any graphics library with FS to paint objects like graphs onto your PDF.
Downsides:
While it does a good job at rendering modern css styles it is not perfect. For instance when I used it the project required the border-radius style to be usable. It wasnt so I had to implement it.
Rendering times and memory consumption are increased (Although I have found it to be quite fast and memory efficient)
More libraires in your project.
Heres an example from the FS website if your ineterested.
https://github.com/flyingsaucerproject/flyingsaucer/blob/master/flying-saucer-examples/src/main/java/PDFRender.java
Related
We are working on creating PDf from HTML which will be printed on Legal Page - It contains financial stamps only for first 3 pages at the top.
So, we need to set big top margin for first 3 pages only for the space of the Financial Stamp and default margin for rest of the pages.
We are using CYaHPConverter for HTML -> PDF conversion which does not support this dynamic margin setup on runtime pdf creation.
Can anyone have any idea how to solve this problem with CSS or HTML. Or, suggest any other convertion library for this dynamic margin setup for different pages?
I tried YaHP-Converter's documentation and other popular library like - Aspose.PDF. But not sure how to pass the margin per page. I also tried Vanilla CSS but failed to get the idea.
I don't know much about YaHP converter, but we can achieve this using the itextPdf library easily.
Here is the link which will help you in setting the different margins for different pages.
Based on personal experience, I suggest you use to itext v7 as it can process complicated HTML documents as well compared to v5. Check this for more information on why should we use v7
Note: itextpdf library is not free for commercial use, please check their site for further license-related information
All the documents generated in our application are generated with java-11 + opensagres
/xdocreport-2.0.2 + Freemarker template engine.
The documents are generated correctly in multiple languages like: Russian and Chinese.
We've observed that when the input is in Cambodian language the Word document generated contains some utility boxes instead of Cambodian characters.
I've explained more in detail the issue here: https://github.com/opensagres/xdocreport/issues/575 , but I didn't receive any answer until now.
Did anyone manage to generate documents containing this language with opensagres ?
Thanks upfront!
The answer was, using Aspose framework(this is not free like opensagres).
The biggest advantages are that in Aspose you can force the framework to use some sets of fonts from the application resources and other great features(like smooth and simple pdf convertions).
The only trouble was that Aspose doesn't have integration with Freemarker template. In our case that meant changing a lot of quite big complex existing documents.
After some analyses and based on Aspose really kind support, we took the decision to use a hybrid solution like:
Documents would be still generated in memory with Opensagres and Freemarker
After that the documents will be loaded with Aspose, and render based on the application resources fonts. The native font for Cambodian characters is Daunpenh Font. This font was placed in application resources.
The full topic can be found here: https://forum.aspose.com/t/support-cambodian-language/252057
I have a sample PDF which is having some placeholders, from which I need to generate PDF with Dynamic values in place of 'placeholders'. I need to do this in Java technologies. What should be the approach?
(Note: sample PDF having placeholders, Table structures, paragraphs, Stylesheets).
We, as iText team, has been receiving this exact question more and more everyday since many people/organisations want to generate custom filled PDF files with data they have. Many of them design forms in PDF and then they fill in the form programmatically. However there are problems with this solution: 1. You need license for a product where you will design the form 2. You need license (if applicable) for the PDF library to fill in the form 3. You (with your team) need to spend time to write the code where you fill in the form 4. You need to repeat all those each time you want to update your form etc. 5. Your form is most likely a static form, meaning that, for example, in case of an invoice you need to foresee how many rows you need to put in your form when designing it. What happens if users have more items than you foresee? You can use XFA forms but you probably know the cost of the designer and all other problems that come along with this deprecated technology.
We, as iText, bring a solution to all those problem just like we did in other tools we have. The solution is called iText DITO in which you design your PDF template in a WYSIWYG browser based editor. No coding is needed. If you want extra styling in your PDF, you can add CSS at any time. You can specify data-binding to elements in your design. Once you are done with your design, your project is basically ready to be deployed. If you need to generate tons of high-quality PDF files based on your template, you will use iText DITO back-end SDK to push your custom data (linking to data binding you have in your template) and your PDF files are created instantly.
I have some PDF template (with header and footer). I want to generate documents that are based on that template.
Is there any way to do that with iText? Thank you
P.S. Right now I am generate a document on-fly i.e. every time I generate header, footer and the context itself.
UPDATE: I have found incredible library called PD4ML. It's not free, but not such expensive, BUT it has really cool features such as HTML2PDF conversion on fly, supports a lot of HTML-CSS tags and has even its own jsp tags library! So I really suggest it when you need something instead of heavy and memory-eating JasperReports.
You can use JasperReports library and the iReport visual designer.
JasperReports use iText to produce PDFs from "jasper" templates, that are XML files (following the jrxml DTD) compiled in java classes, but allows you to use the template for generating MS Office files (with POI), html, etc.
Im not sure with iText, but you can use BIRT for this purpose. http://www.eclipse.org/birt/ Its too much using it just for PDF creation, you can do a lot (more than you can imagine) with it.
If you can choose your template format. I would go with JODReport and JODConverter.
JODReport use an ODT template and fill the mapping in the template with your java code.
JODConverter use LibreOffice to convert such template in PDF or whatever fortmat LibreOffice can handle to export.
You have to be able to use LibreOffice as a service installed remotely on a machine.
I used it back in 2012 but not sure if the project is still active
I've written some Java code using the iText library to generate a PDF report, but specifying the layout seems very manual and takes a lot of time, re-running the code to test small adjustments.
Does anyone know of a report designer for PDFs which would work with Java? It doesn't have to be iText based, that's just what I'm using at the moment.
Yes, JasperReports. It has the iReport visual designer. Also, the API is pretty straightforward.
As far as I know, BIRT is an alternative to JasperReports.
Have in mind that both are complex reporting solutions that support exporting to a number of different formats.
You could look at Docmosis which uses Word or OpenOffice documents to provide the layout and formatting (that is, a template). It has a property you can set that will "watch" templates for changes and automatically process the changes in the background, so you can keep changing a template, then render it again without any code/compile changes.