### .NET API Authentication Source: https://www.iloveapi.com/docs/signature-guides/getting-started Shows how to authenticate a project in .NET using the LovePdfApi class with provided public and secret keys. ```C# var api = new LovePdfApi("PUBLIC_KEY", "SECRET_KEY"); ``` -------------------------------- ### Ruby API Authentication Source: https://www.iloveapi.com/docs/signature-guides/getting-started Illustrates how to authenticate a project in Ruby using the Ilovepdf gem with your public and secret keys. ```Ruby api = Ilovepdf::Ilovepdf.new('PUBLIC_KEY', 'SECRET_KEY'); ``` -------------------------------- ### Node.js API Authentication Source: https://www.iloveapi.com/docs/signature-guides/getting-started Provides an example of authenticating a project in Node.js using the ILovePDFApi class. The secret key is required for this library. ```JavaScript //SECRET_KEY only required for NodeJS library. const api = new ILovePDFApi('PUBLIC_KEY', 'SECRET_KEY'); ``` -------------------------------- ### Authenticate Project with iLoveAPI (.NET) Source: https://www.iloveapi.com/docs/pdf-guides/getting-started This snippet demonstrates how to authenticate a project using the iLoveAPI .NET library by creating an instance of the LovePdfApi class with your public and secret keys. ```C# var api = new LovePdfApi("PUBLIC_KEY", "SECRET_KEY"); ``` -------------------------------- ### Authenticate Project with iLoveAPI (Ruby) Source: https://www.iloveapi.com/docs/pdf-guides/getting-started This snippet illustrates how to authenticate a project using the iLoveAPI Ruby library by initializing the Ilovepdf class with your public and secret keys. ```Ruby api = Ilovepdf::Ilovepdf.new('PUBLIC_KEY', 'SECRET_KEY') ``` -------------------------------- ### PHP API Authentication Source: https://www.iloveapi.com/docs/signature-guides/getting-started Demonstrates how to authenticate a project in PHP for creating signatures or managing requests using iLoveAPI. Requires public and secret keys. ```PHP //If you want to create a new signature $signTask = new SignTask("project_public_key", "private_secret_key"); ``` ```PHP //If you want to manage a new request $signatureRequest = new SignatureManagement("publickey", "secretkey"); ``` -------------------------------- ### Authenticate Project with iLoveAPI (PHP) Source: https://www.iloveapi.com/docs/pdf-guides/getting-started This snippet shows how to authenticate a project using the iLoveAPI PHP library by instantiating the Ilovepdf class with your public and secret keys. ```PHP $api = new Ilovepdf('PUBLIC_KEY','SECRET_KEY'); ``` -------------------------------- ### Authenticate Project with iLoveAPI (Node.js) Source: https://www.iloveapi.com/docs/pdf-guides/getting-started This snippet shows how to authenticate a project using the iLoveAPI Node.js library. It requires both the public and secret keys for authentication. ```JavaScript // SECRET_KEY only required for NodeJS library. const api = new ILovePDFApi('PUBLIC_KEY', 'SECRET_KEY'); ``` -------------------------------- ### Start Response Example Source: https://www.iloveapi.com/docs/api-reference Example JSON response when starting a task, providing server details and a task identifier. ```json { "server": "api11.ilovepdf.com", "task": "g27d4mrsg3ztmnzAgm5d...", "remaining_credits": 1234 } ``` -------------------------------- ### Authenticate Project with PHP Source: https://www.iloveapi.com/docs/image-guides/getting-started This snippet shows how to authenticate your project with iLoveAPI servers using the PHP library. It requires your project ID and secret key to instantiate the Iloveimg class. ```PHP $iloveimg = new Iloveimg('project_id', 'project_secret_key'); ``` -------------------------------- ### Node.js: Full Signature Process Source: https://www.iloveapi.com/docs/signature-guides/basic-example A comprehensive Node.js example demonstrating the entire signature process using the iLovePDF SDK. It includes initializing the API, creating a sign task, adding files, configuring signature elements and signers, and processing the task. ```Node.js import ILovePDFApi from '@ilovepdf/ilovepdf-nodejs'; import ILovePDFFile from '@ilovepdf/ilovepdf-nodejs/ILovePDFFile'; import SignTask from '@ilovepdf/ilovepdf-js-core/tasks/sign/SignTask'; import SignatureFile from '@ilovepdf/ilovepdf-js-core/tasks/sign/elements/SignatureFile'; import Signer from '@ilovepdf/ilovepdf-js-core/tasks/sign/receivers/Signer'; const api = new ILovePDFApi(process.env.PUBLIC_KEY!, process.env.SECRET_KEY!); const task = api.newTask('sign') as SignTask; task.start() .then(() => { const file = new ILovePDFFile(''); return task.addFile(file); }) .then(file => { const signatureFile = new SignatureFile(file, [{ type: 'signature', position: '300 -100', pages: '1', size: 28, }]); return signatureFile; }) .then(signatureFile => { const signer = new Signer('Diego Signer', 'invent@ado.com'); signer.addFile(signatureFile); task.addReceiver(signer); }) .then(() => { return task.process(); }) .then(response => { console.log(response); }); ``` -------------------------------- ### Start Compression Task in Node.js Source: https://www.iloveapi.com/docs/pdf-guides/compress-pdf-api This snippet demonstrates how to start a compression task initiated with the iLovePDF Node.js library. ```JavaScript task.start() ``` -------------------------------- ### Apply Text Watermark Source: https://www.iloveapi.com/docs/image-guides/watermark Sets the text for a watermark and executes the task. This example shows basic text configuration. ```Python my_task_watermark.text = 'iLovePDF' my_task_watermark.execute ``` -------------------------------- ### Compress PDF using Node.js Source: https://www.iloveapi.com/docs/pdf-guides/compress-pdf-api This Node.js example demonstrates the complete process of compressing a PDF file using the iLovePDF library. It includes starting the task, adding a file, processing with 'extreme' compression, downloading the result, and saving it locally. ```JavaScript const task = ilovepdf.newTask('compress') as CompressTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ compression_level: 'extreme' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Start Split Task Execution Source: https://www.iloveapi.com/docs/pdf-guides/split-pdf-api This snippet starts the execution of a previously initialized split task. It's typically followed by adding files and processing them. ```javascript task.start() ``` -------------------------------- ### Set Watermark Opacity (Ruby) Source: https://www.iloveapi.com/docs/image-guides/watermark This Ruby code example demonstrates setting watermark opacity. It configures the watermark text and its transparency level before executing the task. ```Ruby # Select watermark parameters my_task_watermark.transparency = 50 # Execute the task my_task_watermark.execute() ``` -------------------------------- ### Compress PDF - Basic Node.js Source: https://www.iloveapi.com/docs/pdf-guides/compress-pdf-api Provides a Node.js example for compressing PDF files with the iLovePDF API. It uses promises to chain operations like starting the task, adding files, processing, and downloading. ```JavaScript const task = ilovepdf.newTask('compress') as CompressTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process(); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Start Sign Task (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Initiates the sign task process. ```JavaScript task.start() ``` -------------------------------- ### Node.js Office to PDF Conversion Source: https://www.iloveapi.com/docs/pdf-guides/office-to-pdf-api Convert Office documents to PDF using Node.js. This example uses promises to chain operations: starting a task, adding a file, processing, downloading, and saving the PDF locally. ```Node.js const task = ilovepdf.newTask('officepdf') as OfficePdfTask; task.start() .then(() => { const file = new ILovePDFFile('./path/to/file1_name.doc'); return task.addFile(file); }) .then(() => { return task.process(); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Start PDF to JPG Conversion Task (Node.js) Source: https://www.iloveapi.com/docs/pdf-guides/pdf-to-jpg-api This snippet demonstrates how to start a PDF to JPG conversion task using the iLoveAPI library in Node.js. ```JavaScript task.start() ``` -------------------------------- ### PHP: Catch All iLoveAPI Request Errors Source: https://www.iloveapi.com/docs/image-guides/error-handling This example demonstrates how to catch all possible errors from iLoveAPI requests, including start, authentication, upload, process, and download errors, using a single try-catch block with specific exception types. ```PHP try { // start the class manager $iloveimg = new Iloveimg("PUBLIC_KEY", "SECRET_KEY"); // and get the task tool $myTask = $iloveimg->newTask('compress'); // file var keeps info about server file id, name... // it can be used latter to cancel file $file = $myTask->addFile('/path/to/file/document.png'); // and set name for output file. // in this case it will output a zip file, so we set the package name. $myTask->setPackagedFilename('split_documents'); // and name for split document (inside the zip file) $myTask->setOutputFilename('split'); // process files // time var will have info about time spent in process $time = $myTask->execute(); // and finally download file. If no path is set, it will be downloaded on current folder $myTask->download('path/to/download'); // catch possible errors // Start task errors } catch (Ilovepdf\Exceptions\StartException $e) { echo "An error occured on start: " . $e->getMessage() . " "; // Authentication errors } catch (Ilovepdf\Exceptions\AuthException $e) { echo "An error occured on auth: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Uploading files errors } catch (Ilovepdf\Exceptions\UploadException $e) { echo "An error occured on upload: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Processing files errors } catch (Ilovepdf\Exceptions\ProcessException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Downloading files errors } catch (Ilovepdf\Exceptions\DownloadException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Other errors (as connexion errors and other) } catch (Exception $e) { echo "An error occured: " . $e->getMessage(); } ``` -------------------------------- ### Set Watermark Opacity (Node.js) Source: https://www.iloveapi.com/docs/image-guides/watermark This Node.js code example shows how to set watermark opacity using the iLovePDF SDK. It chains promises to start a task, add a file, process with specified text and transparency, download, and save the file. ```JavaScript const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', transparency: 50 }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Set Watermark Opacity (PHP) Source: https://www.iloveapi.com/docs/image-guides/watermark This PHP code example shows how to set the opacity for a watermark. It configures the watermark text and its transparency level before executing the task. ```PHP // Select watermark parameters $myTaskWatermark->setText('iLovePDF'); $myTaskWatermark->setOpacity(50); // Execute the task $myTaskWatermark->execute(); ``` -------------------------------- ### Start HTML to PDF Conversion Task Source: https://www.iloveapi.com/docs/pdf-guides/html-pdf-api This snippet initiates the HTML to PDF conversion process by calling the start() method on the HtmlPdfTask object. ```typescript task.start() ``` -------------------------------- ### Add File and Signature Elements (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Starts a sign task, adds a file, and then defines multiple signature elements (signature, initials, text) with their properties. ```JavaScript import SignatureFile from '@ilovepdf/ilovepdf-js-core/tasks/sign/elements/SignatureFile'; task.start() .then(() => { return task.addFile(''); }) .then(file => { // Multiple elements. const signatureFile = new SignatureFile(file, [ { type: 'signature', position: '300 -100', pages: '1', size: 28, color: '#000000', font: 'Arial-Unicode-MS', }, { type: 'initials', position: '300 -100', pages: '1', size: 28, color: '#000000', }, { type: 'text', position: '300 -100', pages: '1', size: 28, color: '#000000', content: 'This is a text field.', }, ]); return signatureFile; }); ``` -------------------------------- ### Set Signature Tool Language Source: https://www.iloveapi.com/docs/signature-guides/advanced-example This example demonstrates how to set the language for the signature process. The language code should follow standard ISO 639-1 format. ```Ruby my_task.language = "es" ``` -------------------------------- ### Convert Images to PNG using PHP Source: https://www.iloveapi.com/docs/image-guides/convert This example shows how to convert images to PNG format using the iLoveIMG PHP library. By setting the 'to' property to 'png', you can easily change the output format. The process includes task creation, file upload, execution, and download. ```PHP // Create a new task $myTaskConvert = $iloveimg->newTask('convert'); // Add files to task for upload $file1 = $myTaskConvert->addFile('path/to/file1_name.tiff'); $file2 = $myTaskConvert->addFile('path/to/file2_name.png'); // Execute the task $myTaskConvert->execute(); // Download the package files $myTaskConvert->download(); ``` -------------------------------- ### Initialize iLovePDF Signature Tool Source: https://www.iloveapi.com/docs/signature-guides/advanced-example This snippet shows how to initialize the iLovePDF Signature tool with your public and private keys. Ensure you have the 'ilovepdf' gem installed and required. ```Ruby require 'ilovepdf' pub_key = "YOUR_PUBLIC_KEY" priv_key = "YOUR_PRIVATE_KEY" my_task = Ilovepdf::Tool::Signature.new(pub_key, priv_key) ``` -------------------------------- ### .NET Office to PDF Conversion Source: https://www.iloveapi.com/docs/pdf-guides/office-to-pdf-api Convert Office documents (DOCX, XLS) to PDF using .NET. This example shows task creation, file addition, processing, and downloading the PDF. It utilizes the iLovePDF .NET library. ```.NET // Create a new task var taskConvertOffice = api.CreateTask(); // Add files to task for upload var file1 = taskConvertOffice.AddFile("path/to/file/file1_name.docx"); var file2 = taskConvertOffice.AddFile('path/to/file1_name.xls'); // Execute the task taskConvertOffice.Process(); // Download the package files taskConvertOffice.DownloadFile(); ``` -------------------------------- ### Enable Watermark Mosaic (Node.js) Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api Provides an example of enabling the watermark mosaic in Node.js. The code chains promises to manage the watermark task, including adding a file, processing with mosaic enabled, and downloading the output. ```Node.js const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', mosaic: true }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Convert Images to Animated GIF using PHP Source: https://www.iloveapi.com/docs/image-guides/convert This example demonstrates converting images to an animated GIF using the iLoveIMG PHP library. You can specify the output format as 'gif_animation' and configure animation speed ('gif_time') and looping ('gif_loop'). The process includes task creation, file upload, parameter setting, execution, and download. ```PHP // Create a new task $myTaskConvert = $iloveimg->newTask('convert'); // Add files to task for upload $file1 = $myTaskConvert->addFile('path/to/file1_name.jpg'); $myTaskConvert->setTo('gif_animation'); $myTaskConvert->setGifTime(50); $myTaskConvert->setGifLoop(true); // Execute the task $myTaskCompress->execute(); // Download the package files $myTaskCompress->download(); ``` -------------------------------- ### Initialize Compress Task in Node.js Source: https://www.iloveapi.com/docs/pdf-guides/compress-pdf-api This snippet shows the initialization of a new compression task using the iLovePDF Node.js library. ```JavaScript const task = ilovepdf.newTask('compress') as CompressTask; ``` -------------------------------- ### Manage Signature Tokens Source: https://www.iloveapi.com/docs/signature-guides/manage-example Sets up tokens for signature and receiver management. ```PHP $signatureToken = "signaturetoken"; $receiverToken = "receivertoken"; ``` -------------------------------- ### API Response Example Source: https://www.iloveapi.com/docs/api-reference Example of a successful API response indicating task completion, including file details and processing time. ```json { "download_filename": "output.zip", "filesize": 0, "output_filesize": 0, "output_filenumber": 2, "output_extensions": "[\"pdf\"]", "timer": "0.028", "status": "TaskSuccess" } ``` -------------------------------- ### Get Receiver Information Source: https://www.iloveapi.com/docs/signature-guides/manage-example Fetches information about a specific receiver using their token. ```PHP // Get information about a specific receiver: $signatureRequest->getReceiverInfo($receiverToken); ``` -------------------------------- ### Ruby: Send Document for Signing Source: https://www.iloveapi.com/docs/signature-guides/basic-example Sends the prepared document with signature elements and signers to be processed by the iLovePDF service. ```Ruby body = my_task.send_to_sign.body ``` -------------------------------- ### Apply Watermark with Mosaic (PHP) Source: https://www.iloveapi.com/docs/image-guides/watermark Applies a watermark with a mosaic effect using PHP. Sets the watermark text and enables the mosaic feature before execution. ```PHP // Select watermark parameters $myTaskWatermark->setText('iLovePDF'); $myTaskWatermark->setMosaic(true); // Execute the task $myTaskWatermark->execute(); ``` -------------------------------- ### Initialize Signature Management Source: https://www.iloveapi.com/docs/signature-guides/manage-example Initializes the SignatureManagement class with your API keys. ```PHP use Ilovepdf\SignatureManagement; $signatureRequest = new SignatureManagement("publickey", "secretkey"); ``` -------------------------------- ### Initialize Signature Management in Ruby Source: https://www.iloveapi.com/docs/signature-guides/manage-example Initializes the Signature Management client with public and private keys. This is the first step before making any API calls. ```ruby require "bundler/setup" require 'ilovepdf' signature_management = Ilovepdf::Signature::Management.new(pub_key, priv_key) ``` -------------------------------- ### Set Watermark Horizontal Position (Node.js) Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api Provides an example of setting the watermark's horizontal position in Node.js using the iLovePDF API. It chains promises to start a task, add a file, process the watermark with horizontal positioning, and download the result. ```Node.js const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', horizontal_position: 'left' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Add Text Watermark to PDF (Node.js) Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api Shows how to add a text watermark to a PDF file using the iLovePDF API in Node.js. This example utilizes promises for asynchronous operations, including starting the task, adding the file, processing with text, and downloading the result. ```JavaScript const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Compress PDF - Basic Ruby Source: https://www.iloveapi.com/docs/pdf-guides/compress-pdf-api Illustrates PDF compression using Ruby and the iLovePDF API. The code covers task creation, file addition, execution, and downloading the compressed files. ```Ruby # Create a new task my_task_split = ilovepdf.new_task :compress # Add files to task for upload file1 = my_task_compress.add_file('path/to/file1_name.pdf') file2 = my_task_compress.add_file('path/to/file2_name.pdf') # Execute the task my_task_compress.execute # Download the package files my_task_compress.download ``` -------------------------------- ### Download Signature Files Source: https://www.iloveapi.com/docs/signature-guides/manage-example Downloads audit, original, and signed files for a signature request to the local filesystem. ```PHP // Download the audit file on the filesystem $signatureRequest->downloadAuditFile($signatureToken, "./", "audit3"); // Download the original files on the filesystem: $signatureRequest->downloadOriginalFiles($signatureToken, "./", "original3"); // Download the created signed files on the filesystem: $signatureRequest->downloadSignedFiles($signatureToken, "./", "signed4"); ``` -------------------------------- ### Number PDF Pages with Specific Range and Starting Number Source: https://www.iloveapi.com/docs/api-reference Number specific pages within a PDF, starting from a designated number. This example numbers pages from 3 to the end, beginning the count at 1. ```Page Numbering pages = "3-end" starting_number = 1 ``` -------------------------------- ### Download Files Source: https://www.iloveapi.com/docs/pdf-guides/common-features Demonstrates how to download processed output files from a specified folder. The download functions mirror the basic upload functionalities. ```PHP $myTask->download('foldername/folder1/'); ``` ```.NET task.DownloadFile("foldername/folder1/"); ``` ```Ruby my_task.download 'foldername/folder1/' ``` ```Node.js const data = await myTask.download(); fs.writeFileSync('foldername/folder1/', data); ``` -------------------------------- ### Download Signed File in Ruby Source: https://www.iloveapi.com/docs/signature-guides/manage-example Downloads the signed version of the document. Similar to the original file, the output can be a PDF or a ZIP archive depending on the number of input files. ```ruby signature_token = "SIGNATURE_TOKEN" path = signature_management.download_signed(signature_token,"/tmp/",create_directory: true, filename: "signed") ``` -------------------------------- ### Apply Text Watermark with Rotation Source: https://www.iloveapi.com/docs/image-guides/watermark Applies a text watermark with a specified rotation angle. This example uses Python. ```Python my_task_watermark.text = 'iLovePDF' my_task_watermark.rotate = 30 my_task_watermark.execute ``` -------------------------------- ### Import SignatureFile (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Imports the SignatureFile class for creating signature elements. ```JavaScript import SignatureFile from '@ilovepdf/ilovepdf-js-core/tasks/sign/elements/SignatureFile'; ``` -------------------------------- ### PHP: Handle iLovePDF API Errors Source: https://www.iloveapi.com/docs/pdf-guides/error-handling This example demonstrates how to catch various exceptions that can occur during iLovePDF API operations, such as starting a task, authentication, uploading files, processing, and downloading. It uses a series of specific catch blocks for detailed error reporting and a general catch block for any other unexpected errors. ```PHP try { // start the class manager $ilovepdf = new Ilovepdf("PUBLIC_KEY", "SECRET_KEY"); // and get the task tool $myTask = $ilovepdf->newTask('split'); // file var keeps info about server file id, name... // it can be used latter to cancel file $file = $myTask->addFile('/path/to/file/document.pdf'); // set ranges to split the document $myTask->setRanges("2-4,6-8"); // and set name for output file. // in this case it will output a zip file, so we set the package name. $myTask->setPackagedFilename('split_documents'); // and name for split document (inside the zip file) $myTask->setOutputFilename('split'); // process files // time var will have info about time spent in process $time = $myTask->execute(); // and finally download file. If no path is set, it will be downloaded on current folder $myTask->download('path/to/download'); // catch possible errors // Start task errors } catch (IlovepdfExceptionsStartException $e) { echo "An error occured on start: " . $e->getMessage() . " "; // Authentication errors } catch (IlovepdfExceptionsAuthException $e) { echo "An error occured on auth: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Uploading files errors } catch (IlovepdfExceptionsUploadException $e) { echo "An error occured on upload: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Processing files errors } catch (IlovepdfExceptionsProcessException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Downloading files errors } catch (IlovepdfExceptionsDownloadException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Other errors (as connexion errors and other) } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } ``` -------------------------------- ### JavaScript: Initialize API with File Encryption Source: https://www.iloveapi.com/docs/pdf-guides/encrypt-api This JavaScript code snippet demonstrates how to initialize the iLoveAPI client with public and secret keys, and crucially, how to set a file encryption key during initialization for secure file handling. ```javascript const ilovepdf = new ILovePDFApi( 'PUBLIC_KEY', 'SECRET_KEY', { file_encryption_key: '0123456789012345', } ); ``` -------------------------------- ### Apply Text Watermark with Mosaic Source: https://www.iloveapi.com/docs/image-guides/watermark Applies a text watermark with a mosaic effect, creating a 3x3 matrix of the watermark across the document. This example uses Python. ```Python my_task_watermark.text = 'iLovePDF' my_task_watermark.mosaic = true my_task_watermark.execute ``` -------------------------------- ### Retrieve Signature Lists Source: https://www.iloveapi.com/docs/signature-guides/manage-example Fetches a list of all created signature requests, with options for pagination. ```PHP // Get a list of all created signature requests $signatureRequest->getSignaturesList(); // Get the first page, with max number of 50 entries per page (default is 20, max is 100). $signatureRequest->getSignaturesList(0, 50); ``` -------------------------------- ### Get Server and Task ID Source: https://www.iloveapi.com/docs/api-reference Retrieves the assigned server and task ID for a given tool and region. This is the initial step to start a process with the iLovePDF API. ```URL https://api.ilovepdf.com/v1/start/{tool}/{region} ``` -------------------------------- ### Configure Signature Tool Branding Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Learn how to add your company's branding, including a name and logo, to the signature process. The logo should be a valid image file path. ```Ruby my_task.add_brand(name: "my company name",logo: "/path/to/logo/logo.png") ``` -------------------------------- ### .NET: Set File Encryption Source: https://www.iloveapi.com/docs/pdf-guides/encrypt-api This .NET code snippet shows how to initialize the iLoveAPI, create a task, set file encryption parameters with a key, process the task, and download the resulting file. It's designed for developers working with .NET. ```csharp // Create a new task (with any tool) var task = api.CreateTask(); // Set auto encrypt your files to true var parameters = new BaseParams( { FileEncryptionKey = "1234123412341234" }; // Execute the task // Download the processed files decrypted task.Process(parameters); task.DownloadFile(); ``` -------------------------------- ### Instantiate ILovePDFApi (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Creates an instance of ILovePDFApi using environment variables for public and secret keys. ```JavaScript const api = new ILovePDFApi(process.env.PUBLIC_KEY!, process.env.SECRET_KEY!); ``` -------------------------------- ### Set Watermark Layer Depth (Ruby) Source: https://www.iloveapi.com/docs/image-guides/watermark This Ruby code example demonstrates setting the watermark layer depth. It configures the watermark text and its layer position before executing the task. ```Ruby # Select watermark parameters my_task_watermark.text = 'iLovePDF' my_task_watermark.layer = 'below' # Execute the task my_task_watermark.execute ``` -------------------------------- ### Set Watermark Layer Depth (PHP) Source: https://www.iloveapi.com/docs/image-guides/watermark This PHP code example demonstrates how to set the layer depth for a watermark. It configures the watermark text and its position (e.g., 'below') before executing the task. ```PHP // Select watermark parameters $myTaskWatermark->setText(‘iLovePDF’); $myTaskWatermark->setLayer('below'); // Execute the task $myTaskWatermark->execute(); ``` -------------------------------- ### PHP: Rotate Image Before PDF Conversion Source: https://www.iloveapi.com/docs/pdf-guides/jpg-to-pdf-api This PHP example demonstrates how to rotate an image before converting it to a PDF using the iLovePDF API. It sets the rotation for a file object to 270 degrees. ```php $file1->setRotation(270); ``` -------------------------------- ### List Signatures in Ruby Source: https://www.iloveapi.com/docs/signature-guides/manage-example Fetches a list of all signature requests with pagination support. You can specify the current page and the number of items per page. ```ruby list = signature_management.list_signatures(current_page: 0,per_page: 20).body ``` -------------------------------- ### Crop Image with PHP Source: https://www.iloveapi.com/docs/image-guides/crop This PHP code snippet demonstrates how to crop an image using the iLoveIMG REST API. It shows how to initialize a new crop task, add a file, set crop coordinates and dimensions, execute the task, and download the result. ```PHP $myTask = $iloveimg->newTask('crop'); $file = $myTask->addFile('path/to/file_name.jpg'); $myTask->setX(10); $myTask->setY(10); $myTask->setWidth(25); $myTask->setHeight(50); $myTask->execute(); $myTask->download(); ``` -------------------------------- ### Set Watermark Vertical Position Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api Illustrates how to control the vertical placement of a watermark on a PDF page. Options include 'bottom', 'top', and 'middle'. The example shows setting the watermark to the 'bottom' position. ```PHP $myTaskWatermark->setText('iLovePDF'); $myTaskWatermark->setVerticalPosition('bottom'); $myTaskPageNumbers->execute(); ``` ```.NET var parameters = new WatermarkParams( new WatermarkModeText("iLovePDF")) { VerticalPosition = WatermarkVerticalPositions.bottom }; taskWatermark.Process(parameters); ``` ```Ruby my_task_watermark.text = 'iLovePDF' my_task_watermark.vertical_position = 'bottom' my_task_watermark.execute ``` ```Node.js const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', vertical_position: 'bottom' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Import Witness (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Imports the Witness class for defining witnesses. ```JavaScript import Witness from '@ilovepdf/ilovepdf-js-core/tasks/sign/receivers/Witness'; ``` -------------------------------- ### Add Text Watermark with Opacity Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api This snippet demonstrates how to set the opacity for a text watermark. It provides examples in PHP, Node.js, and Ruby, illustrating how to configure the transparency level before executing the watermark task. ```PHP // Select watermark parameters $myTaskWatermark->setText('iLovePDF'); $myTaskWatermark->setOpacity(50); // Execute the task $myTaskWatermark->execute(); ``` ```Node.js const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', transparency: 50 }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` ```Ruby # Select watermark parameters my_task_watermark.transparency = 50 # Execute the task my_task_watermark.execute(); ``` -------------------------------- ### Initialize iLovePDF API and Sign Task (JavaScript) Source: https://www.iloveapi.com/docs/signature-guides/advanced-example Initializes the iLovePDF API with public and secret keys and creates a new sign task. ```JavaScript import ILovePDFApi from '@ilovepdf/ilovepdf-nodejs'; import SignTask from '@ilovepdf/ilovepdf-js-core/tasks/sign/SignTask'; const api = new ILovePDFApi(process.env.PUBLIC_KEY!, process.env.SECRET_KEY!); const task = api.newTask('sign') as SignTask; ``` -------------------------------- ### C#: Convert Image to PDF with Margin Source: https://www.iloveapi.com/docs/pdf-guides/jpg-to-pdf-api This C# code example shows how to set a margin of 20 units for an image-to-PDF conversion using the iLovePDF API. It creates a task and processes it with the specified margin. ```csharp var taskImageToPDF = api.CreateTask(); taskImageToPDF.Process(new ImageToPdfParams(Margin = 20)); ``` -------------------------------- ### Node.js: Rotate Image Before PDF Conversion Source: https://www.iloveapi.com/docs/pdf-guides/jpg-to-pdf-api This Node.js example shows how to rotate an image before converting it to a PDF using the iLovePDF API. It sets the rotation parameter for the file to 270 degrees and then processes the conversion. ```javascript const task = ilovepdf.newTask('imagepdf') as ImagePdfTask; task.start() .then(() => { const file = new ILovePDFFile('path/to/file1_name.jpg'); file.params.rotate = 270; return task.addFile(file); }) .then(() => { return task.process(); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Convert PDF to PDF/A in Ruby Source: https://www.iloveapi.com/docs/pdf-guides/pdf-to-pdfa This Ruby code snippet illustrates the process of creating a PDF to PDF/A conversion task, uploading a PDF file, running the conversion, and downloading the output using the iLovePDF API. ```Ruby my_task = ilovepdf.new_task :pdfa file1 = my_task.add_file 'path/to/file1_name.pdf' my_task.execute my_task.download ``` -------------------------------- ### Add Text Watermark with Specific Pages Source: https://www.iloveapi.com/docs/pdf-guides/watermark-pdf-api This snippet shows how to add a text watermark to a PDF, specifying which pages to apply it to. It includes examples for PHP, Node.js, and Ruby, demonstrating parameter selection and task execution. ```PHP // Select watermark parameters $myTaskWatermark->setText('iLovePDF'); $myTaskWatermark->pages('1,6,9'); // Execute the task $myTaskWatermark->execute(); ``` ```Node.js const task = ilovepdf.newTask('watermark') as WatermarkTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ text: 'myWatermarkText', pages: '1,6,9' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` ```Ruby # Select watermark parameters my_task_watermark.text = 'iLovePDF' my_task_watermark.pages '1,6,9' # Execute the task my_task_watermark.execute ``` -------------------------------- ### Upload File from Local Path Source: https://www.iloveapi.com/docs/pdf-guides/common-features Demonstrates how to upload a file from a local file path using the addFile method. This is applicable across PHP, .NET, Ruby, and Node.js. ```PHP $file=$myTask->addFile('path/to/file_name.pdf'); ``` ```Net var file = task.AddFile("path/to/file/file_name.pdf"); ``` ```Ruby file = my_task.add_file 'path/to/file_name.pdf' ``` ```Node.js const file = new ILovePDFFile(path.resolve(__dirname, './path/to/file_name.pdf')); myTask.addFile(file); ``` -------------------------------- ### Ruby: Add Files and Signature Elements to Receiver Source: https://www.iloveapi.com/docs/signature-guides/advanced-example This Ruby snippet shows how to add files to the signature task and then create signature elements for specific files. It demonstrates setting positions, page ranges, and sizes for Signature, Date, Initials, Input, Name, and Text elements, and associating them with a receiver. ```Ruby # File object keeps information about its server_filename and the properties you can set file1 = my_task.add_file '/path/to/file/sample.pdf' file2 = my_task.add_file '/path/to/file/sample2.pdf' signer = Ilovepdf::Signature::Receiver.new(:signer,'name','email@email.com') signer.phone = "34677231431" #Phone number with the country prefix at the beginning => "+34677231431", make sure you have enough credits. signer.phone = "34677231431" #Phone number with the country prefix at the beginning => "+34677231431", make sure you have enough credits. signature_element = Ilovepdf::Signature::SignatureElement.new(file1) signature_element.set_position(x: 20,y: -20) signature_element.pages = "1,2" signature_element.size = 40 signer << signature_element date_element = Ilovepdf::Signature::DateElement.new(file1) date_element.set_position(x: 30,y: -40) date_element.pages = "1-3" date_element.size = 10 signer << date_element initials_element = Ilovepdf::Signature::InitialsElement.new(file1) initials_element.set_position(x: 20,y: -20) initials_element.pages = "1,2" initials_element.size = 40 signer << initials_element input_element = Ilovepdf::Signature::InputElement.new(file2,"Input your ID Number", "Please, fill in your ID Number") input_element.set_position(x: 20,y: -20) input_element.pages = "1-3,4-10" input_element.size = 30 signer << initials_element name_element = Ilovepdf::Signature::NameElement.new(file1) name_element.set_position(x: 300,y: -200) name_element.pages = "3-5,6-10" name_element.size = 40 signer << initials_element text_element = Ilovepdf::Signature::TextElement.new(file2,"This is a text field") text_element.set_position(x: 20,y: -20) text_element.pages = "1" text_element.size = 40 signer << text_element ``` -------------------------------- ### Set Horizontal Position of Page Numbers (Node.js/JavaScript) Source: https://www.iloveapi.com/docs/pdf-guides/page-numbers-pdf-api This example demonstrates setting the horizontal position of page numbers to 'left' using the iLovePDF API in Node.js/JavaScript, including starting the task, adding files, processing, and downloading. ```javascript const task = ilovepdf.newTask('pagenumber') as PageNumberTask; task.start() .then(() => { return task.addFile('path/to/file1_name.pdf'); }) .then(() => { return task.process({ horizontal_position: 'left' }); }) .then(() => { return task.download(); }) .then((data) => { fs.writeFileSync('path/to/local/file_name.pdf', data); }); ``` -------------------------------- ### Convert PDF to PDF/A in C# Source: https://www.iloveapi.com/docs/pdf-guides/pdf-to-pdfa This C# code snippet shows how to initiate a PDF to PDF/A conversion task, add a file for processing, execute the conversion, and download the resulting file using the iLovePDF API. ```C# var taskPDFtoPDFA = api.CreateTask(); var file1 = taskPDFtoPDFA.AddFile("file1.pdf"); taskPDFtoPDFA.Process(); taskPDFtoPDFA.DownloadFile(); ```