Encrypt PDFs
Encrypt and password protect your PDF document using the pdf endpoint.
Encrypting and password protecting a PDF is a breeze using The DynamicPDF API's pdf
endpoint. Setting password protection and encrypting a PDF requires only a few lines of JSON or a few lines of code if using a client library. The following examples illustrate adding security to a PDF via a direct call to the pdf
endpoint.
Check out Getting Started and Task Roadmap if you are new to The DynamicPDF API.
Refer to the documentation outlining security (JSON Instructions Schema - Security).
The DynamicPDF API supports AES-256, AES-128, and RC4-128 encryption.
Calling Endpoint Directly
{
"author":"CeteSoftware",
"creator":"DynamicPDF Cloud Api",
"security":{
"userPassword":"myuser",
"ownerPassword":"mypassword",
"allowCopy":false,
"allowEdit":true,
"allowPrint":false,
"allowUpdateAnnotsAndFields":true,
"allowAccessibility":true,
"allowFormFilling":false,
"allowHighResolutionPrinting":true,
"allowDocumentAssembly":false,
"type":"aes256"
},
"flattenAllFormFields":false,
"retainSignatureFormFields":false,
"inputs":[
{
"resourceName":"fw4.pdf",
"type":"pdf"
}
]
}
Calling Endpoint Using Client Library
The following example illustrates adding security to a PDF using the client libraries.
See Instructions Overview for more information on The DynamicPDF API and security.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
public static Pdf SecurityExample(String basePath) {
Pdf pdf = new Pdf();
PdfResource pdfResource = new PdfResource(basePath + "DocumentA.pdf");
pdf.AddPdf(pdfResource);
Aes256Security sec = new Aes256Security("myuser", "mypassword");
sec.AllowCopy = false;
sec.AllowPrint = false;
pdf.Security = sec;
return pdf;
}
static async SecurityExample(apiKey, basePath) {
var fileResource = basePath + "DocumentB.pdf";
var userName = "myuser";
var passWord = "mypassword";
var pdf = new Pdf();
var pdfResource = new PdfResource(fileResource);
pdf.addPdf(pdfResource);
var sec = new Aes256Security(userName, passWord);
sec.allowCopy = false;
sec.allowPrint = false;
pdf.security = sec;
await this.ProcessAndSave(pdf, apiKey, "json-SecurityExample-output.pdf");
}
public static Pdf SecurityExample(String basePath) {
String fileResource = basePath + "/DocumentB.pdf";
String userName = "myuser";
String passWord = "mypassword";
Pdf pdf = new Pdf();
PdfResource pdfResource = new PdfResource(fileResource);
pdf.addPdf(pdfResource);
Aes256Security sec = new Aes256Security(userName, passWord);
sec.setAllowCopy(false);
sec.setAllowPrint(false);
pdf.setSecurity(sec);
return pdf;
}
public static function SecurityExample() {
$fileResource = InstructionsExample::$BasePath . "DocumentB.pdf";
$userName = "myuser";
$passWord = "mypassword";
$pdf = new Pdf();
$pdfResource = new PdfResource($fileResource);
$pdf->AddPdf($pdfResource);
$sec = new Aes256Security($userName, $passWord);
$sec->AllowCopy = false;
$sec->AllowPrint = false;
$pdf->Security = $sec;
return $pdf;
}
func securityExample(basePath string) *endpoint.Pdf {
secPdf := endpoint.NewPdf()
secRes := resource.NewPdfResourceWithResourcePath(basePath+"DocumentA.pdf", "DocumentA.pdf")
secInput := input.NewPdfWithResource(secRes)
security := endpoint.NewAes128Security("user", "owner")
secPdf.Security = endpoint.Security(security.Security)
secPdf.Inputs = append(secPdf.Inputs, secInput)
return secPdf
}
def ug_security_example(documentPath):
fileResource = documentPath + "DocumentB.pdf"
userName = "myuser"
passWord = "mypassword"
pdf = Pdf()
resource = PdfResource(fileResource)
pdf.add_pdf(resource)
sec = Aes256Security(userName, passWord)
sec.allow_copy = False
sec.allow_print = False
pdf.security = sec
return pdf
The pdf
endpoint takes a JSON instructions document that provides instructions for creating, transforming, merging, and formatting inputs into a combined PDF. Refer to documentation on the instructions schema for information on how to use the pdf
endpoint.