In today’s digital world, protecting sensitive documents is more important than ever. VeryPDF DRM Protector offers a powerful solution to ensure that PDFs are securely protected with DRM encryption. With the ability to automate PDF uploads and DRM protection via the command line, you can integrate this functionality into your existing system. Below, we’ll show you how to set up a PHP script that uses cURL to upload a PDF file and apply DRM protection settings automatically.
What You Need
- VeryPDF DRM Protector: Make sure you have access to the VeryPDF DRM Protector service.
- PHP: You’ll need PHP installed on your system to run the script.
- cURL: Ensure that you have
curl.exe
installed and configured on your system.
Complete examples (include curl.exe, php.exe, etc.) can be downloaded from download web page,
https://drm.verypdf.com/downloads/
The PHP Script for Uploading and Protecting PDFs
The PHP script provided below is designed to automatically upload a PDF file and apply DRM protection via the VeryPDF DRM Protector API. It includes parameters for encryption, watermarks, password protection, expiration dates, and more.
<?php
// Check if a PDF file is provided via command line
if ($argc < 2) {
die(“Error: No PDF file specified. Usage: php drm-protector.php <PDF file path>\n”);
}
// Get the PDF file path from the command line argument
$pdfFilePath = $argv[1];
// Check if the file exists
if (!file_exists($pdfFilePath)) {
die(“Error: The file ‘$pdfFilePath’ does not exist. Please provide a valid file path.\n”);
}
// Define the curl command path
$curl_path = dirname(__FILE__) . ‘/curl/curl.exe’;
// Check if curl.exe exists
echo(“Checking curl path: $curl_path\n”);
if (!file_exists($curl_path)) {
die(“Error: curl.exe not found. Please ensure curl is installed and the path is correct.\n”);
}
// Build the curl command
$curl_command = “\”$curl_path\” ” .
‘-X POST “https://online.verypdf.com/app/pdfdrm/web/upload.php” ‘ .
‘-F “InputFileType=LocalFile” ‘ .
‘-F “Email=support@verypdf.com” ‘ .
‘-F “EnablePDFEncryption=on” ‘ .
‘-F “PasswordForInputPDFFile=” ‘ .
‘-F “UserPassword=d58mG8bX0r8AsgiH” ‘ .
‘-F “OwnerPassword=Z88hgBQ5esfP5eC7” ‘ .
‘-F “PDFCompatibility=6” ‘ .
‘-F “EnableDRMProtection=on” ‘ .
‘-F “VeryPDFDRM_IsNeedInternet=ON” ‘ .
‘-F “VeryPDFDRM_ClientTimeZone=1” ‘ .
‘-F “Check_VeryPDFDRM_LogonID_01=ON” ‘ .
‘-F “VeryPDFDRM_LogonID_01=Demo” ‘ .
‘-F “Check_VeryPDFDRM_Password_01=ON” ‘ .
‘-F “VeryPDFDRM_Password_01=Demo” ‘ .
‘-F “Check_VeryPDFDRM_ExpireAfterDate=ON” ‘ .
‘-F “VeryPDFDRM_ExpireAfterDate=2025/04/10 11:39” ‘ .
‘-F “VeryPDFDRM_DenyPrint=ON” ‘ .
‘-F “VeryPDFDRM_DenyClipCopy=ON” ‘ .
‘-F “VeryPDFDRM_DenySave=ON” ‘ .
‘-F “VeryPDFDRM_DenySaveAs=ON” ‘ .
‘-F “Check_VeryPDFDRM_SetIdleTime=ON” ‘ .
‘-F “VeryPDFDRM_SetIdleTime=300” ‘ .
‘-F “Check_VeryPDFDRM_CloseAfterSeconds=ON” ‘ .
‘-F “VeryPDFDRM_CloseAfterSeconds=300” ‘ .
‘-F “Check_VeryPDFDRM_TitleOfMessage=ON” ‘ .
‘-F “VeryPDFDRM_TitleOfMessage=VeryPDF DRM Reader” ‘ .
‘-F “Check_VeryPDFDRM_DescriptionOfMessage=ON” ‘ .
‘-F “VeryPDFDRM_DescriptionOfMessage=Welcome to use VeryPDF DRM Reader…” ‘ .
‘-F “Check_VeryPDFDRM_ExpireAfterViews=ON” ‘ .
‘-F “VeryPDFDRM_ExpireAfterViews=10” ‘ .
‘-F “Check_VeryPDFDRM_ExpirePrintCount=ON” ‘ .
‘-F “VeryPDFDRM_ExpirePrintCount=10” ‘ .
‘-F “Check_VeryPDFDRM_SetInvalidPWCount=ON” ‘ .
‘-F “VeryPDFDRM_SetInvalidPWCount=10” ‘ .
‘-F “Check_VeryPDFDRM_PDFExpiryDelete=ON” ‘ .
‘-F “VeryPDFDRM_LimitIP=78.137.214.118” ‘ .
‘-F “TextWatermark_Text=VeryPDF” ‘ .
‘-F “TextWatermark_Color=C0C0C0” ‘ .
‘-F “TextWatermark_X=1” ‘ .
‘-F “TextWatermark_Y=1” ‘ .
‘-F “TextWatermark_OffsetX=0” ‘ .
‘-F “TextWatermark_OffsetY=0” ‘ .
‘-F “TextWatermark_IsTiledText=ON” ‘ .
‘-F “TextWatermark_FontName=Arial” ‘ .
‘-F “TextWatermark_FontSize=0” ‘ .
‘-F “TextWatermark_Opacity=30” ‘ .
‘-F “TextWatermark_Rotate=-45” ‘ .
‘-F “ImageWatermark_File=http://www.verypdf.com/images/coffee.jpg” ‘ .
‘-F “ImageWatermark_X=1” ‘ .
‘-F “ImageWatermark_Y=1” ‘ .
‘-F “ImageWatermark_OffsetX=0” ‘ .
‘-F “ImageWatermark_OffsetY=0” ‘ .
‘-F “ImageWatermark_Width=0” ‘ .
‘-F “ImageWatermark_Height=0” ‘ .
‘-F “ImageWatermark_Scale=100” ‘ .
‘-F “ImageWatermark_Opacity=10” ‘ .
‘-F “ImageWatermark_Rotate=0” ‘ .
‘-F “PDFWatermark_File=http://www.verypdf.com/images/pdf/StandardBusiness.pdf” ‘ .
‘-F “PDFWatermark_PDFPage=1” ‘ .
‘-F “PDFWatermark_X=1” ‘ .
‘-F “PDFWatermark_Y=1” ‘ .
‘-F “PDFWatermark_OffsetX=0” ‘ .
‘-F “PDFWatermark_OffsetY=0” ‘ .
‘-F “PDFWatermark_Width=100” ‘ .
‘-F “PDFWatermark_Height=100” ‘ .
‘-F “PDFWatermark_Scale=100” ‘ .
‘-F “PDFWatermark_Opacity=50” ‘ .
‘-F “PDFWatermark_Rotate=0” ‘ .
‘-F “LineWatermark_X1=0” ‘ .
‘-F “LineWatermark_Y1=100” ‘ .
‘-F “LineWatermark_X2=1000” ‘ .
‘-F “LineWatermark_Y2=100” ‘ .
‘-F “LineWatermark_Opacity=50” ‘ .
‘-F “LineWatermark_Rotate=0” ‘ .
‘-F “LineWatermark_Width=1” ‘ .
‘-F “LineWatermark_Color=FF0000” ‘ .
‘-F “LocalFile[]=@‘ . realpath($pdfFilePath) . ‘”‘;
// Execute the curl command
echo(“Executing the following command:\n$curl_command\n”);
$output = shell_exec($curl_command);
// Save the output to output.html in the current directory
echo($output);
file_put_contents(‘output.html’, $output);
// Inform the user
echo “Output has been saved to ‘output.html’.\n”;
?>
How It Works
- PDF File Upload: The script takes the PDF file path as a command-line argument and checks if the file exists.
- cURL Command: It then constructs a cURL command to send the PDF file to the VeryPDF DRM Protector API, applying various DRM protection options such as encryption, watermarking, password protection, and more.
- DRM Settings: The DRM settings are customizable through the cURL command, including options for restricting print, copy, save, and adding watermarks or expiration dates.
- Automated Processing: Once the cURL command is executed, the response from the API is saved to
output.html
, allowing you to verify the success of the operation.
Benefits of Integrating This into Your System
- Automation: Automatically protect PDFs as they are generated or uploaded.
- Customization: Tailor DRM protection settings to meet your needs, such as setting password requirements, expiry dates, and watermarking.
- Time-Saving: Eliminates the need for manual intervention when applying DRM protection to multiple documents.
Conclusion
Integrating VeryPDF DRM Protector’s command-line PDF upload and protection functionality into your system provides a seamless way to ensure your documents are securely protected. Whether you’re managing large volumes of sensitive data or simply want to automate the document protection process, this solution offers a powerful and flexible method to safeguard your PDFs.