https://www.verypdf.com/app/javascript-to-pdf-embedder-cmd/index.html
- Create a security policy using "Advanced > Security > Manage Security Policies..." menu (available in Acrobat Pro and above). This security policy can apply password protection or restrict access rights.
- Create an Acrobat batch sequence using "Advanced > Document Processing > Batch Processing..." menu (available in Acrobat Pro and above).
- Add a "JavaScript" / "Execute JavaScript" batch command to the batch sequence. Add JavaScript code that applies security policy that you have created in
step 1 (see code sample below). - Apply security to PDF documents by executing this batch sequence.
Use the following code to apply an existing security policy to a PDF document. Make sure to change the name of the security policy (SimplePassword in the example below) to one of your existing policies.
/* Applying a Security Policy to a PDF Document */
/* You need to create a security policy before running this script */
/* Use "Advanced > Security > Manage Security Policies" menu */
var ApplySecurity = app.trustedFunction(
function()
{
var oMyPolicy = null;
var sPolicyName = "SimplePassword"; // Replace "SimplePassword" with your policy name
app.beginPriv();
// First, Get the ID of SimplePassword security policy
var aPols = security.getSecurityPolicies();
for(var i=0; i<aPols.length; i++)
{
if(aPols[i].name == sPolicyName)
{
oMyPolicy = aPols[i];
break;
}
}
if(oMyPolicy != null)
{
// Now, Apply the security Policy
var rtn = this.encryptUsingPolicy({oPolicy: oMyPolicy });
if(rtn.errorCode != 0)
{
// Print error message into JavaScript Debugger Console
console.println("Security Error: " + rtn.errorText);
}
}
app.endPriv();
});
ApplySecurity();
You can save above JS code to a text file, you can run following command line to insert this Javascript code into PDF file,
addjs2pdf.exe -runatopen js.txt in.pdf out.pdf
out.pdf file will contain the Javascript code, when you open this PDF file in Adobe Acrobat software, above Javascript code will be executed automatically.