I have a PDF file that is produced as part of a help file compilation. There is always late breaking stuff which goes into a text file (e.g. "What's new in this version" type of stuff) and while Help and Manual allows you to include stuff from a text file it only works for the CHM output and not for the PDF.

I'm wondering if I can do it by generating a unique placeholder string instead and then using some tool (I may need to write one) to do a search and replace of that unique string with the contents of the late breaking info text file.

Is this feasible? Or will it break some sort of internal structure?

  • 1
    When you replace a text string by another one, you have to keep track of the changing text length. This influences at least two internal PDF key properties and structures: (1) the xref table which represents the internal ToC of the objects, noting down the byte-offset of object starting points; (2) the /Length key 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. – Kurt Pfeifle Jun 22 '11 at 6:05
  • 1
    Perhaps it's time to look at another product, like HelpNDoc or Precision Helper. There's also Delphi components for dealing with PDFs that might do what you need, like PowerPDF or one of the items from About.com's list – afrazier Jun 22 '11 at 12:20
  • LibreOffice Draw works quite well for most things nowadays. – Nemo Oct 12 at 7:17
  • @nemo - please explain how LibreOffice Draw could be used to do this. – rossmcm Oct 13 at 23:48
  • @rossmcm I have limited experience in using LibreOffice Draw. I only know that every time I open a PDF file in LibreOffice I manage to edit or remove the parts I need without effort. – Nemo Oct 14 at 15:37
up vote 5 down vote accepted

"It Depends."

You'll probably need a couple things: First of all, the text can't have been rasterized. If that's the case, then all bets are off. Second, the entire font must have been embedded. If the font was subsetted (which is most often the case) then you may not have the required glyphs. Finally, you'd probably want to limit the size of the textarea being modified to be as small as possible, just to prevent having to deal with large amounts of reflow. You'd want as much whitespace around the plcaeholder as possible.

Now, this probably won't be something that you'll be able to do with a simple text editor, but there might be some PDF maniulating tools that can do the substiution for you.

  • Hmmmm.... Reflow is exactly what I don't want. There are 2 things I want to embed - one is the version ( - that should be no big deal. The other is a text file - i.e. formatted with line breaks - I guess I would need to add some \n's. Unfortunately poking around the PDF with a text editor I can't see any text blocks. I'm sure the file is not rasterized - I can select text with the mouse for example. – rossmcm Jun 22 '11 at 1:16
  • The content is almost certainly compressed, so you won't be able to find your text quite so readily. – afrazier Jun 22 '11 at 1:45
  • yes, I guess that's it. There are large lumps of binary in the file. I guess I'm stumped. – rossmcm Jun 22 '11 at 2:11

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
        // step 4
        // Add text with a local destination
        Paragraph p = new Paragraph();
        Chunk top = new Chunk("Country List", FilmFonts.BOLD);
        // 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 ");
        // 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));
        // 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")));
                PdfAction.gotoRemotePage("movie_links_1.pdf", rs.getString("country_id"), false, true));
        // Add text with a local goto
        p = new Paragraph("Go to ");
        top = new Chunk("top");
        top.setAction(PdfAction.gotoLocalPage("top", false));
        // step 5
        // Close the database connection
  • 1
    I'm willing to get my hands dirty, but not quite that dirty... I'm using Delphi. It's a shame there is no port - it looks to be pretty comprehensive. – rossmcm Jun 22 '11 at 5:01
  • Get a freelancer. Works in Java, can call it as a process – tgkprog Jun 5 '17 at 8:05

You can use (Open Source) qpdf utility (available for Linux, Windows and MacOS X) to unpack the PDF into a more readable format. From there you can go and try some of the other advices from the other answers:

qpdf.exe ^
   --qdf ^
     input.pdf ^

The file oUtput.pdf will have uncompressed object streams, all objects re-numbered and re-sorted in an ascending order, and some helpful comments sprinkled into the file. The file can be edited in a text editor (if it doesn't mess with the remaining binary sections).

pdfedit might do the trick - to quote the blurb on their sourceforge site

Free editor for PDF documents. Complete editing of PDF documents is possible with PDFedit. You can change raw pdf objects (for advanced users) or use many gui functions. Functionality can be easily extended using a scripting language (ECMAScript)

As of June 2013, there are *nix and Windows versions.

  • Windows unfortunately – rossmcm Jun 22 '11 at 2:00
  • it allegedly works in cygwin or colinux/andlinux but i've never gotten it to work, – Journeyman Geek Jun 22 '11 at 2:34

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.