Getting Exported Annotations (Highlights, Underlines, Notes, etc) from PDF Expert in the right order

Buddha: Holding onto anger is like drinking poison and expecting the other person to die.
Me taking notes: Buddha says make sure you give the poison to the OTHER guy.
@UnFitz

When reading PDFs on the iPad (or iPhone) with PDF Expert, you can simply highlight passages that interest you. If you put the PDF back on the Mac, you can export the Annotations (File > Export Annotation Summary As … > Text).

However, sometimes the order of the Highlights deviates from the page order. It’s not even in reverse, just that some notes are in the wrong place.

Here’s how you can sort them quickly (as usual, without warranty). I’ll use BBEdit for it.

If you only used Highlight:

  1. Open the text file with the exported annotations in BBEdit.
  2. Save it under a new name (just to be sure if something goes wrong).
  3. Use Search > Find (or Cmd + f) and look for \r and replace it with BREAKHERE. The idea is reformat the lines that each line holds one highlight (starting with “Highlight [page …]”). This step turns the whole document into one (very long) line. The \r is simply a linebreak (\n is also sometimes used).
  4. Replace Highlight [page with \rHighlight [page. Now you should have one line for each exported highlight (and underline, and note).
  5. Now use Text > Sort Lines … and make sure that “Numbers match by value” and “Sorted lines replace selection” is checked. Nothing else. The “Numbers match by value” should ensure that, e.g., 18 comes before 110. The Highlights should now be in the right order.
  6. Add the breaks you removed by replacing BREAKHERE with \r.
  7. Optional: If you want to remove the page numbers, just activate the Grep checkbox and replace, e.g., “Highlight \[page [0-9]*\]: ” with nothing (leave the replace field blank). (If Grep is activated, the \ masks the [, so it actually searches for a “[“, and the [0-9] means it looks for numbers between 0 and 9, and the * means there can be more than one number.)

    Remember to untick the Grep checkbox after you’re done.

If you used Highlight and other annotations, e.g., Underline or Notes:

Given that Text > Sort Lines goes by the first letters of the line, it will group all Highlights, all Underlines, and all Notes together. To get them sorted by page number, we need to change the order of {Highlight|Underline|Note} and page number.

  1. Open the text file with the exported annotations in BBEdit.
  2. Save it under a new name (just to be sure if something goes wrong).
  3. Use Search > Find (or Cmd + f) and look for \r and replace it with BREAKHERE.
  4. Replace Highlight \[page ([0-9]*)\]: (mind the additional brackets, they store the result and make it available with \1) with p. \1 (highlight):.
    Then Underline \[page ([0-9]*)\]: with p. \1 (underline):,
    and Note \[page ([0-9]*)\]: with p. \1 (note):.
  5. Now use Text > Sort Lines … and make sure that “Numbers match by value” and “Sorted lines replace selection” is checked. Nothing else.
  6. Add the breaks you removed by replacing BREAKHERE with \r.

One possible disadvantage: Multiple highlights on the same page might get out of order, as the Text > Sort Lines will just go by the order of the alphabet. Still, helps to bring the notes into a manageable order.