Java - Creating PDF from template

Murali

Limp Gawd
Joined
Nov 2, 2004
Messages
282
Hi everyone,

I'm trying to create PDFs from Templates in Java. I have an application that generates schedules for students. I want to be able to fill in a template with that schedule, and then generate a PDF of it.

I have absolutely no idea how to go about this... I'd like to use MS Word or OpenOffice Writer for the template, but from what I can find, Java has no way of manipulating either of these file formats without having Word or Writer installed on the server.

Ideas?
 
I have not... I'll look into this... thanks!

The option I started looking into was saving the Word 2010 file into .xml and manually parsing the XML for the pages... every page other than the first and last are very easy to distinguish and play with.

This might be a better solution... thanks again!
 
We do this at work, except we use C#. We use a 3rd party library to handle interfacing with the pdfs directly. There are a few free ones available for Java also.

Basically, you make the PDF in Acrobat Pro, putting in fields for each of spaces on the pdf that you need to put data into. Then you load up the pdf with library and tell it to set certain fields with values.

Lets say you had a grid with 4 columns and 10 rows. You'd create fields on the pdf for each cell in the grid name each cell like 1A, 1B, 1C, 1D, 2A, 2B, 2C, 2D, etc.

Then in code, you could do like something like:
Code:
for(int i = 0; i < classes.length; i++)
{
    pdf.set(i.tostring() + "A", classes[i].Name);
    pdf.set(i.tostring() + "B", classes[i].CourseNumber);
    pdf.set(i.tostring() + "C", classes[i].Teacher);
    pdf.set(i.tostring() + "D", classes[i].Room);
}
 
AlienKing, that sounds exactly like what I want... Do you know of any Java packages that do it?

iText seems like it would, but I can't find too many examples. It'll fill out a PDF form, and flatten them, but the final document still looks like it was a form.
 
iText seems like it would, but I can't find too many examples. It'll fill out a PDF form, and flatten them, but the final document still looks like it was a form.

Filling it out and flattening meet our requirements, so I've never tried to do more.

No idea about other java packages.
 
Ended up using a docx saved as an XML... Did some figuring out of how a page is displayed as XML, and just iterated that a bunch of times, and replaced the special spots with String manipulation.

Worked well enough.

Thanks for your help!
 
Back
Top