How to copy bookmarks from one PDF to another

35 sec read

How to copy bookmarks from one PDF to another

JPedal already has the ability to read bookmarks from PDF files so now you can chain this functionality with our OutlineWriter to copy bookmarks from one PDF to another.

How to Copy bookmarks using Java

  1. Add JPedal to your class or module path. (download the trial jar).
  2. Next, read the outline into a Document object:
    // Read
    final ExtractOutline extract = new ExtractOutline("source.pdf");
    extract.openPDFFile();
    final Document outlines = extract.getPDFTextOutline();
    extract.closePDFfile();
  3. Then, write the Document object to the destination PDF:
    // Write
    final OutlineWriter writer = new OutlineWriter("destination.pdf", outlines);
    writer.writeOutline();
  4. Copy bookmarks using the command line
    JPedal also provides a convenient command line method to copy bookmarks between PDF files:java -jar jpedal.jar --copyoutline "oldfile.pdf" "newfile.pdf"

Working with bookmarks in JPedal

If you are looking to work with Annotations in JPedal, we recommend you start with these tutorials:-