Below is an article aimed at PHP developers who want to automatically upload a PDF to VeryPDF’s online DRM/enciphering service using PHP + cURL. It explains what the example script does, how to run it, and what every POST parameter in the example means, so you can adapt it safely to your system.
Quick summary
The provided drm-protector-phpcurl.php is a CLI PHP script that:
- Accepts a path to a local PDF as a command-line argument.
- Validates the file and environment (checks php-curl).
- Builds a multipart/form-data POST with a large set of DRM, encryption, watermark, and policy options.
- Uploads the file to https://online.verypdf.com/app/pdfdrm/web/upload.php.
- Saves the returned HTML response to output.html and prints the HTTP status.
This is a practical starting point to integrate VeryPDF DRM Protector into a PHP backend or automated workflow.
Run it
From the shell/terminal:
php drm-protector-phpcurl.php /path/to/your/file.pdf
You should see:
Uploading file: /path/to/your/file.pdf
HTTP status: 200
Response saved to output.html
<?php // drm-protector-phpcurl.php // Check if a PDF file is provided as command line argument if ($argc < 2) { die("Error: No PDF file specified. Usage: php drm-protector-phpcurl.php <PDF file path>\n"); } $pdfFilePath = $argv[1]; // Verify file exists if (!file_exists($pdfFilePath)) { die("Error: The file '$pdfFilePath' does not exist. Please provide a valid file path.\n"); } // Ensure curl extension is available if (!extension_loaded('curl')) { die("Error: PHP curl extension is not loaded. Please enable php-curl.\n"); } $realPath = realpath($pdfFilePath); if ($realPath === false) { die("Error: Cannot resolve real path of the file.\n"); } // Target upload URL $url = 'https://online.verypdf.com/app/pdfdrm/web/upload.php'; // Prepare POST fields (equivalent to -F parameters in curl.exe) $postFields = [ 'InputFileType' => 'LocalFile', 'Email' => 'demo@verypdf.com', 'EnablePDFEncryption' => 'on', 'PasswordForInputPDFFile' => '', 'UserPassword' => 'd58mG8bX0r8AsgiH', 'OwnerPassword' => 'Z88hgBQ5esfP5eC7', 'PDFCompatibility' => '6', 'EnableDRMProtection' => 'on', 'VeryPDFDRM_IsNeedInternet' => 'ON', 'VeryPDFDRM_ClientTimeZone' => '1', 'Check_VeryPDFDRM_LogonID_01' => 'ON', 'VeryPDFDRM_LogonID_01' => 'Demo', 'Check_VeryPDFDRM_Password_01' => 'ON', 'VeryPDFDRM_Password_01' => 'Demo', 'Check_VeryPDFDRM_ExpireAfterDate' => 'ON', 'VeryPDFDRM_ExpireAfterDate' => (new DateTime('+10 days'))->format('Y/m/d H:i'), 'VeryPDFDRM_DenyPrint' => 'ON', 'VeryPDFDRM_DenyClipCopy' => 'ON', 'VeryPDFDRM_DenySave' => 'ON', 'VeryPDFDRM_DenySaveAs' => 'ON', 'Check_VeryPDFDRM_SetIdleTime' => 'ON', 'VeryPDFDRM_SetIdleTime' => '300', 'Check_VeryPDFDRM_CloseAfterSeconds' => 'ON', 'VeryPDFDRM_CloseAfterSeconds' => '300', 'Check_VeryPDFDRM_TitleOfMessage' => 'ON', 'VeryPDFDRM_TitleOfMessage' => 'VeryPDF DRM Reader', 'Check_VeryPDFDRM_DescriptionOfMessage' => 'ON', 'VeryPDFDRM_DescriptionOfMessage' => 'Welcome to use VeryPDF DRM Reader...', 'Check_VeryPDFDRM_ExpireAfterViews' => 'ON', 'VeryPDFDRM_ExpireAfterViews' => '10', 'Check_VeryPDFDRM_ExpirePrintCount' => 'ON', 'VeryPDFDRM_ExpirePrintCount' => '10', 'Check_VeryPDFDRM_SetInvalidPWCount' => 'ON', 'VeryPDFDRM_SetInvalidPWCount' => '10', 'Check_VeryPDFDRM_PDFExpiryDelete' => 'ON', 'VeryPDFDRM_LimitIP' => '78.137.214.118', 'TextWatermark_Text' => 'VeryPDF', 'TextWatermark_Color' => 'C0C0C0', 'TextWatermark_X' => '1', 'TextWatermark_Y' => '1', 'TextWatermark_OffsetX' => '0', 'TextWatermark_OffsetY' => '0', 'TextWatermark_IsTiledText' => 'ON', 'TextWatermark_FontName' => 'Arial', 'TextWatermark_FontSize' => '0', 'TextWatermark_Opacity' => '30', 'TextWatermark_Rotate' => '-45', 'ImageWatermark_File' => "https://www.verypdf.com/images/coffee.jpg", 'ImageWatermark_X' => '1', 'ImageWatermark_Y' => '1', 'ImageWatermark_OffsetX' => '0', 'ImageWatermark_OffsetY' => '0', 'ImageWatermark_Width' => '0', 'ImageWatermark_Height' => '0', 'ImageWatermark_Scale' => '100', 'ImageWatermark_Opacity' => '10', 'ImageWatermark_Rotate' => '0', 'PDFWatermark_File' => "https://www.verypdf.com/images/pdf/StandardBusiness.pdf", 'PDFWatermark_PDFPage' => '1', 'PDFWatermark_X' => '1', 'PDFWatermark_Y' => '1', 'PDFWatermark_OffsetX' => '0', 'PDFWatermark_OffsetY' => '0', 'PDFWatermark_Width' => '100', 'PDFWatermark_Height' => '100', 'PDFWatermark_Scale' => '100', 'PDFWatermark_Opacity' => '50', 'PDFWatermark_Rotate' => '0', 'LineWatermark_X1' => '0', 'LineWatermark_Y1' => '100', 'LineWatermark_X2' => '1000', 'LineWatermark_Y2' => '100', 'LineWatermark_Opacity' => '50', 'LineWatermark_Rotate' => '0', 'LineWatermark_Width' => '1', 'LineWatermark_Color' => 'FF0000', // File field, using CURLFile for multipart upload 'LocalFile[]' => new CURLFile($realPath) ]; // Initialize cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Return response as a string instead of direct output curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Follow redirects automatically curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Connection and execution timeout curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 300); // Debugging option (enable if needed) // curl_setopt($ch, CURLOPT_VERBOSE, true); echo "Uploading file: $realPath\n"; // Execute request $response = curl_exec($ch); if ($response === false) { $err = curl_error($ch); curl_close($ch); die("cURL error: $err\n"); } // Get HTTP response code $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // Save response to file file_put_contents('output.html', $response); echo "HTTP status: $httpCode\n"; echo "Response saved to output.html\n"; ?>
Prerequisites & security notes
- php-curl extension: The script checks for it. Install/enable if missing.
- CLI invocation: This example is written for CLI ($argc/$argv). To use in web context, adapt input methods (e.g., $_FILES).
- SSL verification: The example sets CURLOPT_SSL_VERIFYPEER = false and CURLOPT_SSL_VERIFYHOST = 0 — this disables certificate checking and is insecure. In production, remove those lines or set them to validate server TLS (recommended).
- Credentials (passwords, emails) in the example are placeholders/demos. Never hard-code real credentials; store secrets in environment variables or secure vaults.
- Rate limits / abuse: If you integrate programmatically, follow the provider’s API/usage rules and add exponential backoff / retries.
- Validate responses: The script writes the whole response to output.html. Parse and assert success status in real integrations.
High-level explanation of the code blocks
- Argument check — ensures the user supplied a path ($argc < 2).
- File existence check — file_exists() and realpath() to ensure correct path.
- cURL availability check — extension_loaded(‘curl’).
- POST target URL — $url = ‘https://online.verypdf.com/app/pdfdrm/web/upload.php’; — the endpoint that receives the multipart upload and DRM options.
- Prepare POST fields — an associative array $postFields of options. The file is attached with new CURLFile($realPath) (multipart upload).
- cURL options & execution — initialize, set URL, POST, POSTFIELDS, SSL options, RETURNTRANSFER, follow redirects, timeouts, execute, handle errors, save output to output.html.
Detailed explanation of every POST field used (what they do and recommended usage)
Note: field names are taken from your example. Some parameters are toggles (presence = ON), others carry values. Replace sample values (emails, passwords, IPs) with your own.
File & input related
- InputFileType: ‘LocalFile’ — indicates the file is uploaded from local machine. Other services may accept URL uploads; adjust accordingly.
- LocalFile[]: new CURLFile($realPath) — the actual PDF file uploaded. The [] implies support for multiple files; you can upload several entries if supported.
Contact / tracking
- Email: ‘demo@verypdf.com’ — an email address to receive notifications or used for logging. Use a real contact for tracking.
PDF encryption basics
- EnablePDFEncryption: ‘on’ — enable standard PDF password encryption.
- PasswordForInputPDFFile: ” — current password for an already-protected input PDF (if your incoming PDF has an open password, set it here).
- UserPassword: ‘d58mG8bX0r8AsgiH’ — PDF user password (when PDF encryption is used). Controls opening the PDF (if used).
- OwnerPassword: ‘Z88hgBQ5esfP5eC7’ — PDF owner password to control permissions (printing, copying).
- PDFCompatibility: ‘6’ — PDF version compatibility level (e.g., 6 ~ PDF 1.6). Use value appropriate for feature support and reader compatibility.
Tip: If you want DRM-only without standard PDF password protection, you may set EnablePDFEncryption off and rely on DRM options (depending on service capabilities).
VeryPDF DRM-specific toggles and policy fields
- EnableDRMProtection: ‘on’ — enable the VeryPDF DRM engine (wraps and enforces DRM policies).
- VeryPDFDRM_IsNeedInternet: ‘ON’ — indicates the DRM-protected file requires online checks (online license validation).
- VeryPDFDRM_ClientTimeZone: ‘1’ — timezone offset or ID used for client license logic. Check provider docs for expected values.
- Check_VeryPDFDRM_LogonID_01: ‘ON’ — enable a login ID check.
- VeryPDFDRM_LogonID_01: ‘Demo’ — the required login/user id string.
- Check_VeryPDFDRM_Password_01: ‘ON’ — enable password check for DRM access.
- VeryPDFDRM_Password_01: ‘Demo’ — DRM password to open/view under the DRM system.
Expiry and usage limits
- Check_VeryPDFDRM_ExpireAfterDate: ‘ON’ — enable expiration by absolute date/time.
- VeryPDFDRM_ExpireAfterDate: (new DateTime(‘+10 days’))->format(‘Y/m/d H:i’) — computed expiry timestamp (example sets expiry 10 days from upload). Format: YYYY/MM/DD HH:MM. Use absolute times in the timezone expected by the service.
- Check_VeryPDFDRM_ExpireAfterViews: ‘ON’ — enable expiry after a number of views.
- VeryPDFDRM_ExpireAfterViews: ’10’ — number of views after which access is revoked.
- Check_VeryPDFDRM_ExpirePrintCount: ‘ON’ — enable limiting the number of prints.
- VeryPDFDRM_ExpirePrintCount: ’10’ — allowed print count before printing disabled.
- Check_VeryPDFDRM_SetInvalidPWCount: ‘ON’ — enable counting invalid password attempts.
- VeryPDFDRM_SetInvalidPWCount: ’10’ — number of allowed invalid password attempts.
- Check_VeryPDFDRM_PDFExpiryDelete: ‘ON’ — enable deletion of the protected file or remote revocation when expired.
- VeryPDFDRM_LimitIP: ‘78.137.214.118’ — optional IP address restriction; if present, only that IP (or IP list if supported) may open the document. Replace or remove for no IP restriction.
Permissions (deny / allow)
- VeryPDFDRM_DenyPrint: ‘ON’ — disallow printing.
- VeryPDFDRM_DenyClipCopy: ‘ON’ — disallow copy/paste of text or clipping.
- VeryPDFDRM_DenySave: ‘ON’ — disallow saving the opened file locally.
- VeryPDFDRM_DenySaveAs: ‘ON’ — disallow “Save As” behavior.
Use these to build a fine-grained permission policy. Keep in mind enforcement depends on the DRM reader used by end users.
Idle / Auto-close policies
- Check_VeryPDFDRM_SetIdleTime: ‘ON’ — enable idle timeout.
- VeryPDFDRM_SetIdleTime: ‘300’ — idle time (seconds) before the document becomes inaccessible.
- Check_VeryPDFDRM_CloseAfterSeconds: ‘ON’ — enable forced close after this many seconds.
- VeryPDFDRM_CloseAfterSeconds: ‘300’ — number of seconds after which viewer forcibly closes.
On-screen messages
- Check_VeryPDFDRM_TitleOfMessage: ‘ON’ — show a title for DRM message.
- VeryPDFDRM_TitleOfMessage: ‘VeryPDF DRM Reader’ — text shown as message title.
- Check_VeryPDFDRM_DescriptionOfMessage: ‘ON’ — enable description text.
- VeryPDFDRM_DescriptionOfMessage: ‘Welcome to use VeryPDF DRM Reader…’ — descriptive message shown to users.
Watermarks (text)
- TextWatermark_Text: ‘VeryPDF’ — the watermark text.
- TextWatermark_Color: ‘C0C0C0’ — hex color code (silver in this example).
- TextWatermark_X, TextWatermark_Y: ‘1’ — position anchor (how the service interprets coordinates depends on API).
- TextWatermark_OffsetX, TextWatermark_OffsetY: ‘0’ — fine position offsets.
- TextWatermark_IsTiledText: ‘ON’ — tile the text watermark across pages.
- TextWatermark_FontName: ‘Arial’ — font for text watermark.
- TextWatermark_FontSize: ‘0’ — 0 often means auto-size or default; check service docs.
- TextWatermark_Opacity: ’30’ — opacity percentage (0–100).
- TextWatermark_Rotate: ‘-45’ — rotation angle in degrees.
Watermarks (image)
- ImageWatermark_File: “https://www.verypdf.com/images/coffee.jpg” — remote image URL to use as watermark (or could be an uploaded image field).
- ImageWatermark_X, ImageWatermark_Y: ‘1’ — position anchor.
- ImageWatermark_OffsetX, ImageWatermark_OffsetY: ‘0’.
- ImageWatermark_Width, ImageWatermark_Height: ‘0’ — zero may mean auto-size. Use explicit pixels/percent if supported.
- ImageWatermark_Scale: ‘100’ — scale percent.
- ImageWatermark_Opacity: ’10’ — image watermark opacity percent.
- ImageWatermark_Rotate: ‘0’ — rotation.
PDF-as-watermark (overlay with another PDF)
- PDFWatermark_File: “https://www.verypdf.com/images/pdf/StandardBusiness.pdf” — URL of the PDF to overlay as watermark pages.
- PDFWatermark_PDFPage: ‘1’ — which page of the watermark PDF to use.
- PDFWatermark_X, PDFWatermark_Y: ‘1’ — anchor position.
- PDFWatermark_OffsetX, PDFWatermark_OffsetY: ‘0’.
- PDFWatermark_Width, PDFWatermark_Height: ‘100’ — dimensions; interpret as percent or units per API.
- PDFWatermark_Scale: ‘100’ — percent scaling.
- PDFWatermark_Opacity: ’50’ — overlay opacity.
- PDFWatermark_Rotate: ‘0’.
Line watermark (vector)
- LineWatermark_X1, LineWatermark_Y1, LineWatermark_X2, LineWatermark_Y2 — coordinates for a line overlay.
- LineWatermark_Opacity: ’50’
- LineWatermark_Rotate: ‘0’
- LineWatermark_Width: ‘1’ — stroke width.
- LineWatermark_Color: ‘FF0000’ — red color hex.
cURL options explained (in the script)
- curl_init() — start cURL.
- CURLOPT_URL — target endpoint.
- CURLOPT_POST — use POST.
- CURLOPT_POSTFIELDS — array containing fields and CURLFile for upload. PHP handles boundary/multipart automatically.
- CURLOPT_SSL_VERIFYPEER = false / CURLOPT_SSL_VERIFYHOST = 0 — disables TLS checks (not recommended for production).
- CURLOPT_RETURNTRANSFER = true — return response string rather than output directly.
- CURLOPT_FOLLOWLOCATION = true — follow HTTP redirects.
- CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT — control connect and total operation timeouts (seconds).
- curl_exec — perform request.
- curl_error — fetch error string if failed.
- CURLINFO_HTTP_CODE — get HTTP status code.
What to do with output.html (response)
- The service probably returns an HTML page describing success/error and links to the protected file or license info. In automated systems you should:
- Parse the response for success indicators or JSON (if available).
- Extract any protected-file-id, download URLs, or license IDs.
- Log the response and handle errors programmatically (retry on transient errors, surface permanent errors to admins).
Suggested production improvements / integration tips
- Secure secrets: Move UserPassword, OwnerPassword, and other secrets to environment variables or a secret manager.
- TLS validation: Re-enable SSL verification. Use a custom CA bundle if necessary.
- API keys & authentication: If the provider offers an API token-based endpoint, prefer that over unauthenticated form-upload.
- Error handling: Parse service responses and handle non-200 codes and service-level errors.
- Webhook: If VeryPDF offers callbacks/webhooks upon processing completion, use those for asynchronous handling (upload → process → webhook).
- File scanning: If files are user-submitted, scan for malware before uploading to external services.
- Rate limiting / retries: Add exponential backoff for 5xx or network failures.
- Sanitize inputs: Don’t trust filenames or user-supplied fields; sanitize for logs and storage.
- Multiple files: The form uses LocalFile[], so you can extend to multiple simultaneous uploads if supported.
- Progress & large files: For large PDFs, consider enabling cURL progress callbacks or chunked uploads if the API supports them.
Final notes & checklist
- Replace demo values with production-safe values.
- Re-enable SSL verification.
- Confirm field semantics (some services treat a parameter value of ‘ON’ vs ‘on’ differently; use consistent casing).
- Consult VeryPDF’s official API/docs for additional fields and latest best practices (e.g., JSON API or token-based endpoints).
- Test thoroughly with a staging account before enabling on production.
