1. Go to this page and download the library: Download r0adrunn3r/easy-pnp 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/ */
r0adrunn3r / easy-pnp example snippets
$card_width = 30; // 30mm
$card_height = 60; //60mm
//Arguments are the padding of the pages and the margins of the images respectively.
$epnp = new EasyPnP(5,3);
//You can use URLs or Paths
$img_array = array(
"http://mysite.com/cards/image1.png",
"http://mysite.com/cards/image2.png",
"./cards/image3.png"
);
$epnp->WriteImages($card_width, $card_height, $img_array);
//----------------------------------------------------
//Static helper method for generating an array of imgs paths from a folder
$img_array_folder = EasyPnP::FilesArrayFromDir("./cards");
$epnp->WriteImages($card_width, $card_height, $img_array_folder);
//----------------------------------------------------
/*If your images are organized with a sequence number you can use the FilesArrayFromPattern static helper method
This call for exaple is equivalent to:
$array_img_pattern = array(
"./tokens/token_2.png",
"./tokens/token_3.png",
"./tokens/token_4.png",
"./tokens/token_5.png",
"./tokens/token_6.png",
);
5 images, counter starts from 2
*/
$array_img_pattern = EasyPnP::FilesArrayFromPattern("./tokens/token_%.png",5, 2);
$epnp->WriteImages(20, 20, $array_img_pattern);
//----------------------------------------------------
//You can also use generated images (with PHP GD for example) but *BEFORE* use them make sure to specify the type of file to EasyPnP
$epnp->SetFileType('png');
$img_array_php = array("http://xyz.com/cards.php?id=45","http://xyz.com/cards.php?id=47");
$epnp->WriteImages($card_width, $card_height, $img_array_php);
//----------------------------------------------------
//You can also create a front & back pdf ready to print, the fourth argument can be a single image path or an array of backs, if so the array of front and the array of backs must have the same size
$epnp->WriteImagesDoubleSide($card_width, $card_height, $img_array, "./back.png");
//----------------------------------------------------
//After all the images are writed out you can output the pdf, the first argument is for forcing the download instead of opend it inside the browser.
$pdf->GeneratePDF(true, "printable.pdf");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.