PHP code example of erlangparasu / pdfbox-php-wrapper

1. Go to this page and download the library: Download erlangparasu/pdfbox-php-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erlangparasu / pdfbox-php-wrapper example snippets




rlangParasu\PdfboxPhpWrapper\Pdfbox;

$file1 = 'path/to/your/1.pdf';
$file2 = 'path/to/your/2.pdf';
$outputFile = 'path/to/your/merged-output.pdf';

try {
    $pdfbox = new Pdfbox();

    $result = $pdfbox->addSourcePath($file1)
                     ->addSourcePath($file2)
                     ->setOutputPath($outputFile)
                     ->merge();

    if ($result) {
        echo "Success! Merged PDF created at: $outputFile\n";
    } else {
        echo "Error: Merge operation failed.\n";
    }

} catch (Exception $e) {
    echo "An exception occurred:\n";
    echo $e->getMessage()."\n";
}

$pdfbox = new Pdfbox();

// Use PDFBox v3
$pdfbox->useVersion3();

// All subsequent calls will use the v3 engine
$pdfbox->addSourcePath(...)
       ->merge();

// Switch back to v2 if needed
$pdfbox->useVersion2();

$pdfbox = new Pdfbox();

// Example for Linux/macOS
$pdfbox->setJavaPath('/usr/bin/java');

// Example for Windows
// $pdfbox->setJavaPath('C:\\Program Files\\Java\\jdk-11\\bin\\java.exe');

$pdfbox->addSourcePath(...)
       ->merge();
bash
composer 
json
""erlangparasu/pdfbox-php-wrapper": "dev-main"
},
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/erlangparasu/pdfbox-php-wrapper.git"
    }
],
"minimum-stability": "dev",
"prefer-stable": true