If you are willing to get your hands dirty; iText should work.
There are examples which cover a wide range of topics and should get you pointed in the right direction.
Note the example below; using the document.add method to add a Paragraph into an existing PDF document.
protected void createPdf(String filename)
throws IOException, DocumentException, SQLException {
// Open the database connection
DatabaseConnection connection = new HsqldbConnection("filmfestival");
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
// Add text with a local destination
Paragraph p = new Paragraph();
Chunk top = new Chunk("Country List", FilmFonts.BOLD);
top.setLocalDestination("top");
p.add(top);
document.add(p);
// Add text with a link to an external URL
Chunk imdb = new Chunk("Internet Movie Database", FilmFonts.ITALIC);
imdb.setAction(new PdfAction(new URL("http://www.imdb.com/")));
p = new Paragraph(
"Click on a country, and you'll get a list of movies, containing links to the ");
p.add(imdb);
p.add(".");
document.add(p);
// Add text with a remote goto
p = new Paragraph("This list can be found in a ");
Chunk page1 = new Chunk("separate document");
page1.setAction(new PdfAction("movie_links_1.pdf", 1));
p.add(page1);
p.add(".");
document.add(p);
document.add(Chunk.NEWLINE);
// Get a list with countries from the database
Statement stm = connection.createStatement();
ResultSet rs = stm.executeQuery(
"SELECT DISTINCT mc.country_id, c.country, count(*) AS c "
+ "FROM film_country c, film_movie_country mc WHERE c.id = mc.country_id "
+ "GROUP BY mc.country_id, country ORDER BY c DESC");
// Loop over the countries
while (rs.next()) {
Paragraph country = new Paragraph(rs.getString("country"));
country.add(": ");
Chunk link = new Chunk(String.format("%d movies", rs.getInt("c")));
link.setAction(
PdfAction.gotoRemotePage("movie_links_1.pdf", rs.getString("country_id"), false, true));
country.add(link);
document.add(country);
}
document.add(Chunk.NEWLINE);
// Add text with a local goto
p = new Paragraph("Go to ");
top = new Chunk("top");
top.setAction(PdfAction.gotoLocalPage("top", false));
p.add(top);
p.add(".");
document.add(p);
// step 5
document.close();
// Close the database connection
connection.close();
}
xreftable which represents the internal ToC of the objects, noting down the byte-offset of object starting points; (2) the/Lengthkey for the stream that includes the changed text. Otherwise the file will be regarded as corrupt. Also, to edit text, the full (not subsetted) font must be embedded into the PDF. – pipitas Jun 22 '11 at 6:05