I have hundreds of rich PDFs that need to be generated from my application, they have images and colorful content. I was looking to build a framework which support a template and data model and can take care of rest, so adding anew pdfs would be just adding a new template. In the past i have used free-marker to generate HTML and that print HTML to PDFs, are there any better recent solution to solve this problem?
There are various things you could do:
generate xml data, apply xslt transformation to style it, and convert
the html document to a pdf
code a small class that converts whatever data format you have to a pdf document (you would need to do all the layout through code)
create a template (using whatever design program you want) pdf document, insert form fields, and have iText fill the form (several of our customers go for this approach)
Keep in mind that JasperReports uses a proprietary format. Whereas the approaches I suggested use only open and well-established formats.
Take a look at JasperReports.
Related
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
Which APIs in java help in extracting table metadata from a pdf, and presenting that table in a web page?
The result should be that when the source of page is viewed it will show the html code of that table.
Itext is usefull in this context
http://itextpdf.com/
I assume that, you need a PDF library for Java.
PDFBox is one of the popular libraries created to PDF manipulation and I think it is worth to look at it.
try The Metadata Extract Tool which extracts metadata from specific file types including PDF. Then you can parse the xml output with any Java XML parser. Once you're able to parse it, elements can be easily laid down in your view page.
I have following problem: I have a XML file with XSL stylesheet, that is rendering this XML file as neat table in HTML when I load it in web browser. Now I need to make a PDF that is looking EXACTLY like that XSL-styled XML in web browser, without need for making custom FO's for every file. Everything must be done in Java.
I need to make a PDF that is looking EXACTLY like that XSL-styled XML in web browser
Think again about this requirement. Paged media such as PDF and non-paged media such as HTML may only look "close enough", but never "exactly like" each other. This is even more obvious if you consider your HTML being displayed on devices with different screen sizes.
If you relax the above requirement somewhat, you'll probably agree that XSL-FO is the best choice. You definitely do not need to write "custom FO's for every file": write an XSLT just once, and use it on-the-fly to convert your XML to XSL-FO, and then use a rendering engine to process XSL-FO to PDF. Simple.
XSL-FO does sound like exactly what you need. But if that's not an option, first explicitly doing the XSLT transform on the XML in Java and then converting the resulting HTML (which by then is a String/byte array/DOM/whatever you want) to PDF using some additional library would do the trick. There's some libraries that support HTML to PDF, like iText for example. XSLT transformations in Java are really simple. Little code involved there.
I wrote a web app for generating PDF by filling data into a pre-saved PDF template, template edited by acrobat, with some text-fields. But the context of those text-fields seems in a different layer and cannot affect other existing words in template.
... But I want it affect the existing words and make them flow base on how many data fill into the text-fields.
The solution maybe use program to generate a whole PDF instead of using template. But the template changes really often in my case, I don't want waste a lot of time to adjust the position and format by coding...
Do anyone know how to use text-field with auto flow in a PDF template? just like a Word document.
PDF doesn't work like that. You need to generate the whole PDF.
Ah... but from what?
There are quite a few HTML->PDF converters out there. You could fill in your template HTML, and convert it that way.
You could develop your own input format (for your template), and write an app that reads it and builds a PDF.
The later is similar enough to HTML->PDF, that unless you can't find a converter that handles some PDF feature or other you need, I'd just go that route. There are LOTS of html->pdf apps out there. You can search SO, google, whatever. Lots.