I'm making a utility to grammatically making a document and printing it.
I am gonna apologize, I'm not good at formulating this and there may be some confusion, please bare over with me :(
This project is mostly for making a user friendly utility for creating documents in your program and printing it and also as a learning experience.
It uses objects which I will convert to MarkDown as its easy to work with, I convert it to HTML as its going to be used in a web form.
The problem occurs when I want the program to print this HTML file that i have now created to a PDF.
I've searched for a solution for a very long time but have yet to find results, all that I've found was either out of date, filled with bugs or just could not do what I wanted.
I have tried iText as that seems to be the most popular choice but as stated above, everything I found was out of date and no longer useful, mostly because the classes they speak of do no longer exist.
What I do want is eventually independence of other libraries so that is my ultimate goal, but for now I want a way to print a locally stored HTML file as a PDF, it needs to be CSS compatible.
As an extra thing if anyone could point me in the direction of learning how to make MarkDown to HTML and printing HTML to PDF I would be more than happy.
Edit 1:
Stephan C pointet the question is too wide and difficult to answer, I will try to explain:
Main thing I want is to print a PDF file using an HTML file and CSS which is stored locally.
Optional solutions is I would love to learn how to code this myself instead of implementing libraries, for example markdown4j and iText. Yes I know that's a lot to take on, but as stated this is a learning experience for me.
Have a look at Converting HTML files to PDF. It has sample code for using with iText and also other suggestions. If you run into problems with approach suggested post specifics here. Either modify your original question or ask new question.
Printing directly from HTML to pdf can be also worse than using iText or other libraries.
I just made some iText PDF not using low level pdf classes but compiling a PDF form from it.
If you need to fill a PDF form, you can use iText as following.
Make your html form a PDF form. (acrobat or other free softwares)
Use iText classes AcroFields to get the PDF form fields (you get them by names or you can return a map of fields using AcroFields.getFields();
Compile the required informations using AcroFields.setFields() or .setField();
PdfReader class allow you to open an existing PDF (the template)
PdfStamper allow you to write the stream to another one (the result)
Adding images and other binary stuff is really easy!
By this way, you can do it quickly and layouts will be fast and good too.
The limit is that you need as many template as many data you need. (if you have fields that is some cases are many in other just one, you need twice templates).
For a static number of fields is a good solution.
Hope it helps.
Related
My questions is rather theoretical. I need to implement an application that takes different file extensions such as [asp,bmp,doc,docx,html,jpg,pdf,pdf,png,pptx,sql,txt,xls,xlsx] and converts them all into a consecutive PDF file for print.
I did my research in terms of coding and found multiple libraries that do the job
such as Apache POI, iText, aspose.pdf.jar and others I tested them out on individual portions of the idea. They work great but require a lot of women-hours to implement the desired application. My question is, is there anything more complete that will speed up the job. For example a library such as apache POI that does not require specifying every single padding and background color.
Any suggestions are appreciated.
As per my knowledge and experience not a single API is present there who provide all solution without this. Because of that we need to use Apache POI, iText, aspose.pdf.jar , FOP.
In java(using jquery as per my knowledge) you are able take snapshot of rendered page using stream which you will need to proceed at serverside and generate PDF which generate pdf file same like html page without any extra formatting but it having limitation that you can't use landscape. If page data is big then it shrinks pdf which causes small font(in very large page even you unable to read pdf).
I'm working on a small Scala/Java prototype where I have several PDF templates i.e. they have text and image placeholders and the placeholders should be replaced with some content. Some sections are also multiple i.e. the actual number of occurrences or repetitions depends on the input. Then finally I need to generate and append an extra PDF page.
I'm aware that these use-cases can be covered using iText. My question is whether I can use an alternative solution for this (and how to do it). I'd prefer to avoid commercial solutions for the time being.
UPDATE: I'd like my PDF templates to be created by professional designers. They will know where the placeholders will be but should have full control on the design aspects. This requirement discards solutions based solely on XML inputs or others where the PDF is created fully programmatically.
Jasper - It's sofrware designed for crating dynamic reports connected with database inputs, but I think it can be utilized in the way you want. Has a graphical designer (either iReport or JaspersoftStudio based on your preferences), supports passing multiple variables with content or even images. Long static formatted texts may be a problem, but you will have to judge that for yourself.
JODReports + JODConverter - those two tools will allow your designers to work in pure ODT (OpenOffice format) files putting in dynamic data as variables that you will be able to substitute to your hearts desires from your Java code and print the output in PDF format. More than that, thanks to Java UNO API you can seize full control over the way your template looks and behaves if your inserted texts are really complex (though admittedly it's not intuitive to use).
I have the need to create some pdf through java code, pdf templates are fixed and are very complex too. Each pdf represents a module and I have to fill it with informations I get from other sources in my application and finally create the complete pdf.
So, is there a library which, given a pdf, scans it and creats some java code which will eventually create it back? This way once I get the pdf template in java code I just have to edit it adding my informations and create it back.
You can check these 2 link it's have all information regarding PDF CRUD operation.
How to read PDF files using Java?
http://mrbool.com/how-to-create-write-and-read-pdf-files-using-pdfone-and-java/27058
I have used with success iText http://itextpdf.com/ for various tasks involving creating, parsing and modifying pdf files. Please not that this one is not free for commercial use and the pricing isn't cheap either.
However, your question is a possible duplicate of the folowing one, so be sure to check the answers there:
https://stackoverflow.com/questions/6118635/what-is-the-best-pdf-open-source-library-for-java
itext is one of best approach for your need..
itext API'S
How can I merge individual selected PDF files into one PDF upon download?
I want to achieve the following:
http://annualreport2010.landsecurities.com/create-your-own-report.aspx
Do I require an ASP website, or could I do something similar using a static HTML site?
Static HTML won't do it.
You need something on the server side. The other answers have options that would work, I just wanted to also mention pdftk, which you could then call from the server side. Be sure to escape all file names and such, though, because you would have to use system calls.
pdftk is really easy. The very first example from their documentation shows how to merge several PDFs, named 1.pdf, 2.pdf and 3.pdf, into one PDF called 123.pdf:
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
For PHP, there even is pdftk-php, if you want to look into that.
I think that the Apache PDFBox project can be good for you.
In particular, take a look at the PDFMerger class.
You can also use iText but in my opinion it's less easy to use.
See if itext can help in merging. A quick search gives many links - like Java: Merging multiple PDFs into a single PDF using iText.
There is a Java PDF merging software at http://codesforus.blogspot.com/.
p.s. They link to this download page: http://messiahpsychoanalyst.org/Documents/Downloads.html#part1
You can find Source code for PDF split and Merge Source forge PDF SAM
I want to be able to open up documents containing a combination of one or two pictures and text from java. The documents don't have to be pretty, but I need to be able to switch documents relatively quickly. I'm trying to figure out what the easiest method to do this is.
I can save the documents in whatever format is easiest for me, for instance html or PDF. But the documents must be somewhat easy to modify or generate new ones. I don't care if the document is displayed within a java frame or by an external tool so long as the tool is common enough to be installed on most OS and I can switch documents quickly and without too much hassle. This is an internal tool so it doesn't have to work at professional level quality.
Unfortunately, various company limitations make it a real hassle to get approval to use open source packages that haven't been pre-approved. So I can't do the obvious thing and grab an open source implementation of PDF or HTML reader for java.
So, any suggestions on the easiest format for my documents and how to read it?
You can use XHTML. So, your document will be directory that contains HTML document and image files as-is. you do not need anything beyond JDK to implement this and can use any browser to view such document. Modification is easy too.
Note: I said XHTML as a HTML that can be parsed using regular XML parser. I think it is the best choice for you.