[tool] extract pages with comments  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Mathew
User
Posts: 573
Joined: Thu Jun 19, 2014 7:30 pm

[tool] extract pages with comments  SOLVED

Post by Mathew »

I'm often extracting just the pages with comments from a larger document. There's a very clever built-in way posted here by @PHK: viewtopic.php?p=179698#p179698

But I made a tool that allows selecting the comment author(s) and it generates a new file, with bookmarks to the page ranges. Multiple selection was added in Build 392 so for versions before that you can only select one author.

Installation
Extract the files and save in %APPDATA%\Tracker Software\PDFXEditor\3.0\Javascripts\
extractCommentPages v1.5.zip


Usage
When PDF-XChange is restarted, it adds menu item "Extract Comment Pages…" to the Documents menu, and to the Organize ribbon (ribbon UI).

Open the document you want to copy the pages from, and run the tool. It will show a dialog with a list of all the comment authors. Select whose comments you want to include:
image.png
Include Hidden Comments
If this is unchecked, comments that are on hidden (off) layers, or comments with their Hidden flag set will be excluded when checking if a page should be extracted. Hidden comments are still included if a page has a visible comment by one of the selected authors.

Pick at least one author, then press OK.

The script then creates a new document and adds all the pages that have comments by the selected author(s). It also adds bookmarks to each page range with the page numbers that range came from:
image(1).png
Limitations
  • Multiple selection isn't working yet. Workaround: Use heir_list_box (where it is working).
  • The document should be saved first. It pops up a dialog to warn you. Javascript accesses the saved file when copying page ranges (not the currently open document), so changes in the currently open document that haven't been saved won't be included in the extracted pages.
  • Adding bookmarks is through a workaround that uses the built-in "New Bookmark" menu item, and then tries to figure out which bookmark was added to rename it. Fixed v1.5 Different localizations use different untitled bookmark names, so it needs 1ang.js to get the appropriate translation.
tl;dr
There's an option to compare authors case insensitive: Edit the file on line 30:

Code: Select all

    // author list case sensitive
    const authorsCaseSensitive = false;
The tool is translatable with 1ang.js.
Translation strings are:

Code: Select all

{
 "": {
     "Extract Comment Pages…": "",
     "Extract only pages with comments by selected authors.": "",
     "Extracting pages %1.": "",
     "Warning: The document is not saved. This script extracts pages from the SAVED version.\nDo you want to save the document now?": "",
     "Save Document": "",
     "Select Comment Authors": "",
     "Select comment authors to include in the extracted pages:": "",
     "Hold down SHIFT to select multiple contiguous, CTRL to select multiple discontiguous.": "",
     "Include pages with hidden annotations": "",
     "Making New Document…": "",
     "Adding Bookmarks to new document.": "",
     "Page %1": "",
     "Pages %1-%2": "",
     " from [%1]": "",
     "New Document": ""
 }
}
You do not have the required permissions to view the files attached to this post.
Last edited by Mathew on Sat Apr 05, 2025 10:14 pm, edited 9 times in total.
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2208
Joined: Mon Jan 15, 2018 9:01 am

Re: [tool] extract pages with comments

Post by Dimitar - PDF-XChange »

Thank you, Mathew.
Mathew
User
Posts: 573
Joined: Thu Jun 19, 2014 7:30 pm

Re: [tool] extract pages with comments

Post by Mathew »

Updated to v1.5
extractCommentPages v1.5.zip
Changes since v1.3:
  • update addBookmark to v3 in xutil
  • removed use of doc.extractPages() because it flattens form fields
You do not have the required permissions to view the files attached to this post.
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

@ Mathew: Excellent work in automating again, sir!

In the example of 'author' for the tool that is the subject of this thread, I just was wondering if Comment criteria other than author would be likewise automatable. I, for one, have no use for an author-only tool as I am not part of a work group. But I would find it extremely useful if I could do the same sort of thing for Subjects, for example.

Any possibility?
All best,

FringePhil
Mathew
User
Posts: 573
Joined: Thu Jun 19, 2014 7:30 pm

Re: [tool] extract pages with comments

Post by Mathew »

Absolutely possible. Let me stew on it.
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

Thanks! I am sure that will be appreciated by quite a few in the community.

And I hate to impose on your generosity with another suggestion and I would tackle it myself if I had any idea of how to, but could you consider an automating tool that applies a Bookmark title to the corresponding page thumbnail? I have requested this (see viewtopic.php?p=179173&hilit=titles#p179173) but who knows when it might appear given DevTeam's seeming apparent aversion to creating multi-action user tools.

What I do now is quite simple but tediously repetitive if applying to a file with many pages. I

  • select the Bookmark that points to a page,
  • [F2] to highlight the Bookmark title,
  • [Ctrl-C] to copy the title,
  • select the corresponding Thumbnail,
  • [F2] to open the title field (a number by default),
  • [Ctrl-V] to paste the saved title, and
  • press Enter.
In some instances, I will delete characters of long titles before saving the Thumbnail title for brevity's sake.

I hope this is not too challenging. I am sure many users would appreciate it. Thanking you in advance for considering it.
All best,

FringePhil
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2208
Joined: Mon Jan 15, 2018 9:01 am

[tool] extract pages with comments

Post by Dimitar - PDF-XChange »

It seems like you are finding challenges for Matthew. :)
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

Dimitar - PDF-XChange wrote: Mon Apr 07, 2025 11:44 am It seems like you are finding challenges for Matthew. :)
Yes, I know it's very rude of me. :oops: I sincerely hope he doesn't feel obliged to waste any time on it!
All best,

FringePhil
Mathew
User
Posts: 573
Joined: Thu Jun 19, 2014 7:30 pm

Re: [tool] extract pages with comments

Post by Mathew »

PHK wrote: Mon Apr 07, 2025 2:21 pm Yes, I know it's very rude of me. :oops:
:D not at all! Not very technically difficult to do with a script. Could label a selected range of pages from a (the first?) bookmark found pointing to it, or label the pages that selected bookmarks point to... Both quite different. From the forum post you linked it sounds like you have a ticket approved for an official feature already ;) I'll add it to my list, but I have a few other ideas I want to do first.
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

Thanks, Mathew. Don't bust a gut on this one. Yes, my request seems to be in the Dev mill but I have no idea of the timing. These things sometimes take years unless they are full-blown bugs. But in any case, I fully respect your need to set your own priorities.

As for batch or single, I am usually doing it one Bookmark/Thumbnail at a time but I can see that others might want to do blocks at a time.
All best,

FringePhil
Mathew
User
Posts: 573
Joined: Thu Jun 19, 2014 7:30 pm

Re: [tool] extract pages with comments

Post by Mathew »

Well, we're veering off-topic here, but I took a brief look at doc.setPageLabels( startPage, [ S, P, St]) and the (build 395) implementation requires a following sequence number.

Code: Select all

this.setPageLabels(3,[undefined,"Contents"]);
// Console:Exec:1: RaiseError: RaiseError: The base page object is missing or invalid.
// Doc.setPageLabels:1:Console:Exec
(I also tried null and "" as the style 'S' parameter)
So a javascript tool, unless PXCE fixes it, would have to be something like
My Bookmark Text 1 or My Bookmark Text A or My Bookmark Text i ,etc
which is not very satisfying to me
[edit] Plus, doc.getPageLabel() only returns a string (not absolutely clear that's what's intended because the api says "Page label information for the specified page." but the example script assumes it's at least cooerced to a string that doesn't look like it came from an array. This is problematic because setPageLabels applies to all pages after startPage, so you need to apply it to the page(s) after as well, and to do that you need to know what the setting was for that page.

The PDF Reference does allow the number to be left off, it's just that the javascript tool blocks it:
PDF Reference:

There is no default numbering style; if no S entry is present, page labels consist solely of a label prefix with no numeric portion. For example, if the P entry (below) specifies the label prefix Contents, each page is simply labeled Contents with no page number. (If the P entry is also missing or empty, the page label is an empty string.)
tl;dr
I'm not likely to make a tool unless PXCE fixes doc.setPageLabels() to allow cStyle to be blank and there's a slightly more robust way to determine what the current page labels are.
Last edited by Mathew on Tue Apr 08, 2025 5:45 pm, edited 8 times in total.
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

I feel unequiped to add anything to your observation, Mathew. Perhaps someone at PDFE can contribute some wisdom.
All best,

FringePhil
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11036
Joined: Wed Jan 03, 2018 6:52 pm

Re: [tool] extract pages with comments

Post by Daniel - PDF-XChange »

Hello, PHK

I cant say much myself, but I have raised this to the Dev team for review, hopefully one of them can take a look when they find time, and offer some insight (Or will get me to make a bug/FR ticket if this needs one).

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
User avatar
PHK
User
Posts: 1396
Joined: Tue Nov 24, 2020 4:02 pm

Re: [tool] extract pages with comments

Post by PHK »

Many thanks, Daniel.
All best,

FringePhil
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11036
Joined: Wed Jan 03, 2018 6:52 pm

[tool] extract pages with comments

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com