PHP code example of scrapify-dev / pdf-tools

1. Go to this page and download the library: Download scrapify-dev/pdf-tools 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/ */

    

scrapify-dev / pdf-tools example snippets


use Scrapify\PdfTools\PdfMerge;

$pdfMerge = new PdfMerge();
$pdfMerge->merge(
    [public_path('file1.pdf'), public_path('file2.pdf')],
    public_path('merged.pdf')
);

use Scrapify\PdfTools\PdfSplit;

$pdfSplit = new PdfSplit();
$pdfSplit->split(public_path('file.pdf'), storage_path('app/public/splits'));

use Scrapify\PdfTools\PdfCompressor;

$compressor = new PdfCompressor();
$compressor->compress(public_path('big.pdf'), public_path('small.pdf'));

use Scrapify\PdfTools\OfficeToPdf;

$converter = new OfficeToPdf();
$converter->convert(public_path('document.docx'), public_path('output.pdf'));

use Scrapify\PdfTools\PdfOcr;

$ocr = new PdfOcr();
$text = $ocr->extractText(public_path('scanned.pdf'));

use Scrapify\PdfTools\PdfRotate;

$rotator = new PdfRotate();
$rotator->rotate(public_path('file.pdf'), 90, public_path('rotated.pdf'));

use Scrapify\PdfTools\PdfToImage;

$pdfToImage = new PdfToImage(public_path('file.pdf'));
$pdfToImage->saveImage(public_path('images/page_%d.jpg'));

use Scrapify\PdfTools\ImageToPdf;

$imageToPdf = new ImageToPdf();
$imageToPdf->convert([public_path('img1.png'), public_path('img2.jpg')], public_path('output.pdf'));

use Scrapify\PdfTools\PdfUnlock;

$unlocker = new PdfUnlock();
$unlocker->unlock(public_path('locked.pdf'), 'password', public_path('unlocked.pdf'));

use Scrapify\PdfTools\PdfWatermark;

$watermark = new PdfWatermark();
$watermark->apply(public_path('file.pdf'), public_path('logo.png'), public_path('watermarked.pdf'));

use Scrapify\PdfTools\PdfPageNumber;

$pageNumber = new PdfPageNumber();
$pageNumber->addNumbers(public_path('file.pdf'), public_path('numbered.pdf'));

use Scrapify\PdfTools\PdfRepair;

$repair = new PdfRepair();
$repair->repair(public_path('corrupt.pdf'), public_path('fixed.pdf'));

use Scrapify\PdfTools\PdfToPdfA;

$pdfToPdfA = new PdfToPdfA();
$pdfToPdfA->convert(public_path('file.pdf'), public_path('archival.pdf'));

use Scrapify\PdfTools\PdfProtect;

$protect = new PdfProtect();
$protect->protect(public_path('file.pdf'), 'ownerpass', 'userpass', public_path('protected.pdf'));

use Scrapify\PdfTools\PdfValidatePdfA;

$validator = new PdfValidatePdfA();
$isValid = $validator->validate(public_path('archival.pdf'));

use Scrapify\PdfTools\PdfExtract;

$extract = new PdfExtract();
$extract->extract(public_path('file.pdf'), [1, 3, 5], public_path('extracted.pdf'));

use Scrapify\PdfTools\PdfOrganize;

$organize = new PdfOrganize();
$organize->reorder(public_path('file.pdf'), [3, 1, 2], public_path('reordered.pdf'));

use Scrapify\PdfTools\HtmlToPdf;

$htmlToPdf = new HtmlToPdf();
$htmlToPdf->convert('<h1>Hello</h1>', public_path('output.pdf'));

use Scrapify\PdfTools\PdfEdit;

$editor = new PdfEdit();
$editor->addText(public_path('file.pdf'), 'Confidential', public_path('edited.pdf'));

use Scrapify\PdfTools\PdfToWord;

$pdfToWord = new PdfToWord();
$pdfToWord->convert(public_path('file.pdf'), public_path('output.docx'));