Automating Selected Area Redaction on Multiple Files
Copy link to clipboard
Copied
Hello all,
I'm an intermediate macro-writer but most of my experience has been in vB in Excel, so JS is a bit unfamiliar to me. Apologies if I'm missing something obvious, and any help is appreciated. The task I'm wanting to complete is:
- Identify Scope (Multiple 1-page, identically arranged PDFs)
- Open First File
- Prompt User to draw a Redact Area around some coordinates
- Apply Redactions
- Loop through the remaining documents, applying redaction to the same area.
So far I've been trying to stitch together a few tutorials/pieces of sample code but I'm getting stuck a lot earlier in the process than I expected, hence my reaching out. The code I'm working with is from the below:
https://acrobatusers.com/tutorials/auto_redaction_with_javascript
https://acrobatusers.com/tutorials/apply_security_with_js
https://acrobatusers.com/tutorials/folder_level_scripts
But I can't even get the first pieces of sample code to run exactly as-is on the sample file provided. For the below:
// Part 1: Quads for the different Redaction areas
var qdFirstName = [[0, 195, 179, 195, 0, 181, 179, 181]];
var qdLastName = [[182, 195, 397, 195, 182, 181, 397, 181]];
var qdAdress = [[-1, 172, 273, 172, -1, 158, 273, 158]];
var qdCityState = [[-1, 172, 273, 172, -1, 158, 273, 158]];
var qdSocSec = [[400, 193, 527, 193, 400, 179, 527, 179]];
var qdAlow = [[471, 132, 529, 132, 471, 109, 529, 109]];
var qdExempt = [[413, 72, 529, 72, 413, 60, 529, 60]];
// Part 2: Function for adding Redact Annotations to a PDF function
AddMyRedacts(quadList) {
for(var pg=1; pg<this.numPages; pg++) {
for(var index=0; index<quadList.length; index++) {
this.addAnnot({
type:"Redact", page:pg,
quads:quadList[index],
overlayText: ":It's gone:",
alignment: 1, // center alignment
repeat:true });
}
}
}
// Part3: Applying the redactions
// Code for two different redaction schemes
// Use only one per document
// #1 Run this code to apply redactions to W4 employee name
// and address
AddMyRedacts([qdFirstName, qdLastName, qdAdress, qdCityState, qdSocSec] );
this.applyRedactions({bKeepMarks: false, bShowConfirmation: true, cProgText: "It's going away" });
// #2 Run this code to apply redactions to W4 exemption
// information
AddMyRedacts( [qdAlow, qdExempt, qdSocSec] );
this.applyRedactions({ bKeepMarks: false, bShowConfirmation: true, cProgText: "It's going away" });
When I try to run the first and second piece, it errors immediately with:
SyntaxError: missing ; before statement
10:Console:Exec
undefined
And, being somewhat unclear on the syntax, this is where I'm stuck. Working on Acrobat Pro DC 10. The name of the PDF file is important, otherwise I would simply combine them and then "Apply Mark Across Pages" to redact in one fell swoop.
Copy link to clipboard
Copied
If would be helpful if you posted the code with proper indents so it's easy to read. It would also be helpful if you pointed out the line that is reporting the exception. Counting lines is not only inefficient, but we don't know if the lines are arranged the same here as in your script.
So, where is this code being run? in the console? That would be the right place to test and develop the code
So the first issue is function declaration, it's missing the keyword "function"
Here is the correct code
function AddMyRedacts(quadList) {
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Apologies for the lack of indentation--new to the forum and its formatting. You're right about the reason for the hang, which lets me get the sample to run in the console.
This has allowed me to make some progress. As of now, still working on getting a prompt to the user to draw a rectangular annotation to use as the quad for the redaction area. I may end up abandoning it and just requiring a rectangular annotation to already be present.
Copy link to clipboard
Copied
Use the Alert popup to ask the user to apply a rectangle.
Here's an article on it.
https://acrobatusers.com/tutorials/popup_windows_part1
The Alert is the easy part. The problem is detecting when the rectangle is drawn so the code can get on with the next bit.
The simplest solution is to have two buttons for your process, one to start it by asking the user to apply the redaction, then a second button to apply the redactions.
Another solution is to use a time interval to check for a new rectangle. But this is trickier and has potential problems.
Another solution is to place an invisible page size button on the page to detect mouse events. Effectively creating your own drawing tool. But this is even more complicated.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Change:
AddMyRedacts(quadList) {
To:
function AddMyRedacts(quadList) {

