Background
If more than one person is adding comments to a pdf document, they either have to share a single document (but then it's locked when one person is editing it), or there needs to be a way to merge the comments in multiple documents. Other pdf software has set up subscription-based online editing to handle this, but then you need to trust your documents to their servers, and it's a proprietory solution. A simple brute force method is to export an FDF from all the documents, and import all of them into the document you want. But that will overwrite anything that was changed in the second document, and does not handle deleted comments.
Installation
Extract the zip and save in the Javascripts folder either in the application folder, or in %APPDATA%\Tracker Software\PDFXEditor\3.0\Javascripts
Usage
After restarting PDFX-Change, it will add a button in the "Share" ribbon, (or in the Comments menu in the classic UI): Open the documents you want to merge, and run the tool. It will open a dialog: The left side lists documents that will be merged. If you ran the tool before, it will list the last documents you merged on the left, prefixed with [File] to indicate files that are not currently open. Below the list of files, it shows some brief information about the selected file.
On the right side is a list of the currently open documents. Use the < or > buttons to add or remove documents from the merge list on the left side.
The 'Browse...' button opens a dialog to open a file directly (if you didn't open it before running the tool). PXCE will pop up a security alert before allowing the script to open files. You can stop this for a particular file, directory or drive (I have a server mapped to a drive letter, and under Preferences > Security I added the drive letter as a trusted folder.)
At the top left is a button to set the merge settings. For now, I recommend keeping "Show merge conflicts dialog for all merges" so you can see what it's going to do before the merge happens: Merge Data file
The script can save a data file in the document to improve the speed and accuracy of merges. A saved data file is a file attachment titled 'commentMergeData.txt' that allows the following improvements:
- Keep track of which annotations have been deleted: If there is no data file, the script will assume that if an annotation is missing (i.e. deleted) in one document, that it is new in another document, and will add it back (so to delete an annotation, you'd need to manually delete it in all documents before merge)
- Determine if an annotation has been updated since the previous merge: If there's no merge file, it assumes everything was updated and compares modification dates to all other files. This slows the merge, but if only the modification dates differ, it won't update the annotations in PDFX-Change before build 388.
- (in PDFX-Change before build 388) Keep track of modification dates: When the script adds a missing annotation, it can't set the modification date, so that annotation will appear newer in the next merge; there are cases where this could lead to overwriting changes in another pdf during a subsequent merge. (If only the modification dates differ, it won't update the annotations in PDFX-Change before build 388.)
- Optionally save a log of changes.
Depending on what the merge settings are, a Merge Conflicts dialog will show before the merge starts: For all merges, the script finds the most recently modified annotation, and sets that document as the source for that annotation. Under Merge it will show ?? if there's no default action for that conflict in the settings. You'll need to either set it to Skip or >>>>> (Use Source) to proceed with the merge.
The buttons across the top allow you to set what happens to that annotation in the merge:
- Skip the merge for that annotation,
- Use Source apply the source annotation change to the destination, or
- Change Source move the currently listed destination document to the 'source' (ie revert to an older version)
Limitations/todo
This is a tough nut to crack. Handling the various conflicts is difficult to figure out (for my brain), and there are quite a few aspects of pdfs that are opaque to javascript. I wanted this tool to be able to handle merging more than just two documents at the same time: This makes handling conflicts particularly difficult.
- I've only tested this in PDFX-Change build 391.
- If the documents have different number of pages, the script will fail! I don't know how to know if pages have been moved, inserted, or deleted - the script currently assumes all page numbers between the documents match. I may try something like adding a hidden marker on each page to identify it, but I don't know what the best approach is. There may be some internal identifier to pages that I don't know, or a way to identify them; if you know of a way, please let me know.
- There's no built-in way for javascript to set which comments are in front of the others (ie their z-index). One can work around this by temporarily moving annotations off the page, and back on in the desired order, but haven't added it to this tool yet.
- JavaScript can't add stamps the way it can for other annotations. If you try, the application will look through the currently installed stamps, and try to add the same stamp. This is OK unless the stamp isn't installed on the merging computer or is a pasted image (in which case it will fail) or is a dynamic stamp (in which case it will pop up the dialog associated with that stamp instead of just copying it). I've made a workaround (that requires the source document be saved) copies the whole page, moves the stamp to the desired page and deletes the copied page; but watch out: It requires a registered copy of PXCE! If you want to disable it, edit line 666 and set to false:
Code: Select all
let APPREGISTERED = true; // will only try to use copyStamp function if registered
- There's currently no option whether to restrict merging comments (ie by author, locked, status, etc).
- If two annotations have the same name on the same page number, it will assume they are the same annotation. This will only be a problem if someone manually sets the annotation name.
- The script doesn't currently handle form fields. It could, but I think it would need a 'diff' algorithm to deal with changes to text fields. That could be helpful in dealing with merge conflicts in text annotations also.
- The log is just pasted onto the end of the merge data file and only holds onto one merge. It could be set up to use as a way to revert changes after a merge.
- I'm still fiddling with this tool, so haven't set up a translation data file yet, although the script can handle one.