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.
I've made two tools that overcome this in an open approach: One tool enables multiple files to be merged to all get the most recent markup information; a second "live eXchange" tool runs that first tool on a schedule to synchronize local files with a "central" file. Using the second tool, multiple people adding comments to the same pdf should see the comments that others are adding or editing updated in real time.
Installation
Extract the zip and save in the Javascripts folder either in the application folder, or in %APPDATA%\Tracker Software\PDFXEditor\3.0\Javascripts More detail here: viewtopic.php?p=196006#p196006
This file has both the single merge tool and the live tool: This file is only the single merge tool:
Usage
After restarting PDFX-Change, in the ribbon UI, it adds buttons in the Share ribbon; in the classic UI, they are under File > Merge Tools > (If only the single merge tool is installed, only the "Merge Comments" button will show.)
Live Exchange
See this post below for information on this tool: viewtopic.php?p=200409#p200409
Merge Comments
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.)
Settings
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 either on the computer, or as an attachment in the document to improve the speed and accuracy of merges.
- If saved as a document attachment, it's titled 'commentMergeData.txt'. Requires a registered copy of PDF-XChange.
- [experimental!] If saved on the computer, you need to allow the script to read/write to the file. You'll get a security alert about the script trying to access /C/Users/[User Name]/AppData/Local/Temp/PDFXEdit/CommentMergeData.pdf
- 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, before build 388 (v10.4.0) a bug prevented setting the modification date, so that annotation would 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 before10.4.)
- 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 -->Go--> (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,
- --> Go --> 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 386 & 404.
- 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). The script tries to work around this by temporarily moving annotations off the page, and back on in the desired order.
- 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 (in which case the stamp will be a 'default' stamp
)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).
Code: Select all
let APPREGISTERED = true; // will only try to use copyStamp function if registered - the stamp isn't installed on the merging computer (in which case the stamp will be a 'default' stamp
- 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 is very unlikely if you just allow PXCE to name the markups, but if annotation names are manually set, it could happen.
- 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.