PHP code example of iwasherefirst2 / pretty-pdf

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

    

iwasherefirst2 / pretty-pdf example snippets

 

    $item = new \PrettyPdf\Partials\Invoice\Data\Item();

    $item->description = 'A new currency';
    $item->quantity = 5;
    $item->name = 'Bitcoin';
    $item->unitPrice = 2031.23;

    $paymentInfoDate = new \PrettyPdf\Partials\Invoice\Data\PaymentInfo();

    $paymentInfoDate->title = 'A really good title';
    $paymentInfoDate->description = 'A long description comes in here';
    $paymentInfoDate->bank = 'ING';
    $paymentInfoDate->bic = 'BICXXX';
    $paymentInfoDate->iban = 'DE42 4242 4242 4242 4242 24';
    $paymentInfoDate->name = 'Beauty Bill Creator';

    $bill = new \PrettyPdf\PrettyPdf();

    $bill->logo('/path/to/your/logo.png')
            ->headerInfoBox(['1600 Pennsylvania Ave NW', 'Washington', 'DC 20500', 'United States', 'Beauty Bill Package', '[email protected]'])
            ->returnAddress('Dr. Schwadam, Schwinterfeldschraße 99, 10777 Berlin, Germany')
            ->receiverAddress(['Michael Jackson', 'Colorado Hippo Zoo', '5225 Figueroa Mountain Rd', 'Los Olivos', 'CA 93441', 'United States'])
            ->invoiceBox(['Date' => 'Today', 'Invoice' => 'I 2020-03-22', 'Tax-Number' => '18/455/12345'])
            ->items([$item], 19)
            ->paymentInfo($paymentInfoDate)
            ->additionalNote('Optioanl note. Nothing important here.')
            ->output('/path/where/you/want/to/store/file.pdf');
            
 
 

namespace MyApp\Styles;

class MyOwnStyle extends \PrettyPdf\Partials\Drawable
{
    public function draw(): void 
    {
        // Here you can use all functions from http://www.fpdf.org/ 
        // to draw on your pdf.
        $this->MultiCell(....);
        $this->Cell(...);
        $this->Rect(..);
        
    }
}
 
$prettyPdf = new \PrettyPdf\PrettyPdf();

$prettyPdf->addCustomPartials(['\MyApp\Styles\MyOwnStyle']);
 
$prettyPdf->myOwnStyle()
          ->output('/path/to/file.pdf');   
 


namespace Tests;

use BeautyBill\Partials\Body\Item;

class BeautyBillBodyTest extends BeautyBillTestCase
{
    public function test_body_basic()
    {
        $this->storeOnly = true;
        
        $item = new Item();
        
        $item->description = 'A new currency';
        $item->quantity = 5;
        $item->title = 'Bitcoin';
        $item->unitPrice = 2031.23;

        $this->bill->items([$item]);
        
        $this->assertEqualPDFs('Test.pdf');
    }
}

docker-compose exec app bash
composer install
php vendor/bin/phpunit