adobe javascript to extract annotations
Hello I like the ability Zot has to extract annotations/comments from PDF files.
The following is a script which does the same, but tells you what page the comment is on and removes the author's (of the article) name which is uselessly repeated for each comment. You can hack those pieces out and maybe include it in a future upgrade to Zot if you are using Adobe's javascript at all.
The script below does the above, but additionally if placed in Adobes javascript folder as a config.js file the script will add a permanent menu item under the EDIT menu called 'Comments Report'. The new menu item will create a new PDF file with all of the comments in it from the source PDF file. On my system the config.js file was located at
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
This is useful if you don't happen to use Zot's annotation feature. It's great for seeing all of your highlights and notes in one place.
This code was modified from the original (by George Johnson) at https://community.adobe.com/t5/acrobat-discussions/print-comments-only/td-p/4244927/page/1
app.addMenuItem({
cName: "-",
cParent: "Edit",
cExec: " "
});
// Add a menu item for the comments report function
app.addMenuItem({
cName: "AS_comments_report",
cUser: "Comments Report",
cParent: "Edit",
cExec: "AS_comments_report(this);",
cEnable: "event.rc = app.doc;"
});
AS_comments_report = app.trustedFunction (function (doc) {
if (app.viewerType === "Reader") {
app.beginPriv();
app.alert({
cMsg: "This comment report utility cannot be used with Adobe Reader. It requires Acrobat Pro or Acrobat Standard.",
nIcon: 1, // Warning
cTitle: "Acrobat required"
});
app.endPriv();
return;
}
// Prompt the user for the sorting type
var aSortTypes = [];
aSortTypes.push({cName: "Select a sort type below", bEnabled: false});
aSortTypes.push({cName: "-"});
aSortTypes.push({cName: "None", cReturn: ANSB_None});
aSortTypes.push({cName: "Page #", cReturn: ANSB_Page});
aSortTypes.push({cName: "Author", cReturn: ANSB_Author});
aSortTypes.push({cName: "Date", cReturn: ANSB_ModDate});
aSortTypes.push({cName: "Type", cReturn: ANSB_Type});
var nSortType = app.popUpMenuEx.apply(app, aSortTypes) || ANSB_None;
// Change to true to reverse the sort order
var bReverseOrder = false;
// Specify some page sizes
var PageSize = {
letter_portrait: [0, 11 * 72, 8.5 * 72, 0],
letter_landscape: [0, 8.5 * 72, 11 * 72, 0],
legal_portrait: [0, 14 * 72, 8.5 * 72, 0],
legal_landscape: [0, 8.5 * 72, 14 * 72, 0],
A4_portrait: [0, 11.69 * 72, 8.27 * 72, 0],
A4_landscape: [0, 8.27 * 72, 11.69 * 72, 0]
};
this.syncAnnotScan();
var a = this.getAnnots({nSortBy: nSortType, bReverse: bReverseOrder});
if (a) {
var rep = new Report(PageSize.letter_portrait);
rep.size = 1.8;
rep.color = color.blue;
rep.writeText("Summary of Comments for " + doc.documentFileName);
rep.color = color.black;
rep.writeText(" ");
rep.size = 1.2;
rep.writeText("Total of " + a.length + " comments in this file");
rep.writeText(" ");
rep.writeText(" ");
rep.indent(20);
var msg = "\200 page %s on %s";
for (var i = 0; i < a.length; i++) {
rep.writeText(" ");
if (a[i].contents != null)
{
rep.writeText(util.printf(msg, 1 + a[i].page , util.printd("yyyy/mm/dd", util.scand("yyyy/mm/dd",a.creationDate))));
rep.indent(20);
rep.writeText(a[i].contents);
rep.outdent(20);
}
}
var docReport = rep.open("commentSummary.pdf");
docReport.info.Title = "Comments Summary for " + doc.documentFileName;
}
});
The following is a script which does the same, but tells you what page the comment is on and removes the author's (of the article) name which is uselessly repeated for each comment. You can hack those pieces out and maybe include it in a future upgrade to Zot if you are using Adobe's javascript at all.
The script below does the above, but additionally if placed in Adobes javascript folder as a config.js file the script will add a permanent menu item under the EDIT menu called 'Comments Report'. The new menu item will create a new PDF file with all of the comments in it from the source PDF file. On my system the config.js file was located at
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
This is useful if you don't happen to use Zot's annotation feature. It's great for seeing all of your highlights and notes in one place.
This code was modified from the original (by George Johnson) at https://community.adobe.com/t5/acrobat-discussions/print-comments-only/td-p/4244927/page/1
app.addMenuItem({
cName: "-",
cParent: "Edit",
cExec: " "
});
// Add a menu item for the comments report function
app.addMenuItem({
cName: "AS_comments_report",
cUser: "Comments Report",
cParent: "Edit",
cExec: "AS_comments_report(this);",
cEnable: "event.rc = app.doc;"
});
AS_comments_report = app.trustedFunction (function (doc) {
if (app.viewerType === "Reader") {
app.beginPriv();
app.alert({
cMsg: "This comment report utility cannot be used with Adobe Reader. It requires Acrobat Pro or Acrobat Standard.",
nIcon: 1, // Warning
cTitle: "Acrobat required"
});
app.endPriv();
return;
}
// Prompt the user for the sorting type
var aSortTypes = [];
aSortTypes.push({cName: "Select a sort type below", bEnabled: false});
aSortTypes.push({cName: "-"});
aSortTypes.push({cName: "None", cReturn: ANSB_None});
aSortTypes.push({cName: "Page #", cReturn: ANSB_Page});
aSortTypes.push({cName: "Author", cReturn: ANSB_Author});
aSortTypes.push({cName: "Date", cReturn: ANSB_ModDate});
aSortTypes.push({cName: "Type", cReturn: ANSB_Type});
var nSortType = app.popUpMenuEx.apply(app, aSortTypes) || ANSB_None;
// Change to true to reverse the sort order
var bReverseOrder = false;
// Specify some page sizes
var PageSize = {
letter_portrait: [0, 11 * 72, 8.5 * 72, 0],
letter_landscape: [0, 8.5 * 72, 11 * 72, 0],
legal_portrait: [0, 14 * 72, 8.5 * 72, 0],
legal_landscape: [0, 8.5 * 72, 14 * 72, 0],
A4_portrait: [0, 11.69 * 72, 8.27 * 72, 0],
A4_landscape: [0, 8.27 * 72, 11.69 * 72, 0]
};
this.syncAnnotScan();
var a = this.getAnnots({nSortBy: nSortType, bReverse: bReverseOrder});
if (a) {
var rep = new Report(PageSize.letter_portrait);
rep.size = 1.8;
rep.color = color.blue;
rep.writeText("Summary of Comments for " + doc.documentFileName);
rep.color = color.black;
rep.writeText(" ");
rep.size = 1.2;
rep.writeText("Total of " + a.length + " comments in this file");
rep.writeText(" ");
rep.writeText(" ");
rep.indent(20);
var msg = "\200 page %s on %s";
for (var i = 0; i < a.length; i++) {
rep.writeText(" ");
if (a[i].contents != null)
{
rep.writeText(util.printf(msg, 1 + a[i].page , util.printd("yyyy/mm/dd", util.scand("yyyy/mm/dd",a.creationDate))));
rep.indent(20);
rep.writeText(a[i].contents);
rep.outdent(20);
}
}
var docReport = rep.open("commentSummary.pdf");
docReport.info.Title = "Comments Summary for " + doc.documentFileName;
}
});