PHP code example of lianhua / superpdf

1. Go to this page and download the library: Download lianhua/superpdf 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/ */

    

lianhua / superpdf example snippets


$pdf = new SuperPDF("/path/to/pdf/file");

$pagesCount = $pdf->getPageCount();

$pdf->extractPageRange(3, 7, "path/to/pdf/output");

$pdf->extractPageList([1, 3, 6, 8, 9], "path/to/pdf/output");

$pdf->insertPages("/path/to/pdf/to/insert", 5); // Inserts the PDF at page 5
$pdf->insertPages("/path/to/pdf/to/insert", SuperPDF::AFTER_EACH_PAGE); // Inserts the PDF after each page
$pdf->insertPages("/path/to/pdf/to/insert", SuperPDF::AFTER_ODD_PAGES); // Inserts the PDF after odd pages
$pdf->insertPages("/path/to/pdf/to/insert", SuperPDF::AFTER_EVEN_PAGES); // Inserts the PDF after even pages
$pdf->insertPages("/path/to/pdf/to/insert", SuperPDF::AT_THE_END); // Inserts the PDF after the last page

$pdf->insertPages("/path/to/pdf/to/insert", 5, "/path/to/output");

$pdf->addBackground("/path/to/background/pdf", 5); // Adds a background on page 5
$pdf->addBackground("/path/to/background/pdf", SuperPDF::ON_LAST_PAGE); // Adds a background on last page
$pdf->addBackground("/path/to/background/pdf", SuperPDF::ON_ODD_PAGES); // Adds a background on odd pages
$pdf->addBackground("/path/to/background/pdf", SuperPDF::ON_EVEN_PAGES); // Adds a background on even pages
$pdf->addBackground("/path/to/background/pdf", SuperPDF::ON_EACH_PAGE); // Adds a background on each page

$pdf->addBackground("/path/to/background/pdf", 5, "/path/to/output");

$params = [
    "font" => "arial", // Font family
    "color" => ["r" => 30, "g" => 30, "b" => 30], // Font color
    "pos" => ["x" => 10, "y" => 20], // Text position
    "size" => 15 // Font size
];

$pdf->writeText("Some text", $params, 5); // Writes a text on page 5
$pdf->writeText("Some text", $params, SuperPDF::ON_LAST_PAGE); // Writes a text on last page
$pdf->writeText("Some text", $params, SuperPDF::ON_ODD_PAGES); // Writes a text on odd pages
$pdf->writeText("Some text", $params, SuperPDF::ON_EVEN_PAGES); // Writes a text on even pages
$pdf->writeText("Some text", $params, SuperPDF::ON_EACH_PAGE); // Writes a text on each page

$pdf->writeText("Some text", $params, 5, "/path/to/output");

$params = [
    "x" => 30, // The X position
    "y" => 50, // The Y position
    "w" => 60 // The width (you can also use h)
];

$pdf->drawImage("/path/to/image/file", $params, 5); // Draws an image on page 5
$pdf->drawImage("/path/to/image/file", $params, SuperPDF::ON_LAST_PAGE); // Draws an image on last page
$pdf->drawImage("/path/to/image/file", $params, SuperPDF::ON_ODD_PAGES); // Draws an image on odd pages
$pdf->drawImage("/path/to/image/file", $params, SuperPDF::ON_EVEN_PAGES); // Draws an image on even pages
$pdf->drawImage("/path/to/image/file", $params, SuperPDF::ON_EACH_PAGE); // Draws an image on each page

$pdf->drawImage("/path/to/image/file", $params, 5, "/path/to/output");