mikehaertl\wkhtmlto\Pdf::addPage PHP Method

addPage() public method

Add a page object to the output
public addPage ( string $input, array $options = [], string | null $type = null ) : static
$input string either a URL, a HTML string or a filename
$options array optional options for this page
$type string | null a type hint if the input is a string of known type. This can either be `TYPE_HTML` or `TYPE_XML`. If `null` (default) the type is auto detected from the string content.
return static the Pdf instance for method chaining
    public function addPage($input, $options = array(), $type = null)
    {
        $options = $this->processOptions($options);
        $options['inputArg'] = $this->processInput($input, $type);
        $this->_objects[] = $options;
        return $this;
    }

Usage Example

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // this is where we will initiate the generation process
     // which we'll eventually do by calling an appropriate class to
     // integrate the data received into a PDF and then passing it back to the manager
     // or even more likely, by firing an event and then having a series of listeners respond to it
     // for now ...
     $view = view('documents.chase-letter')->with('document', $this->document)->render();
     $dataPDF = storage_path('app/tmp-' . $this->document['reference'] . '.pdf');
     $finalPDF = storage_path('app/' . $this->document['reference'] . '.pdf');
     // create PDF
     try {
         $pdf = new Pdf(['binary' => '/usr/bin/wkhtmltopdf', 'margin-top' => 0, 'margin-right' => 0, 'margin-bottom' => 0, 'margin-left' => 0, 'commandOptions' => ['enableXvfb' => true]]);
         $pdf->addPage($view);
         $pdf->saveAs($dataPDF);
     } catch (Exception $e) {
         Log::error('Could not create PDF: ' . $pdf->getError());
     }
     // stamp it
     try {
         $pdftk = new Pdftk(base_path('resources/assets/docs/cluster-template.pdf'));
         $pdftk->stamp($dataPDF);
         $pdftk->saveAs($finalPDF);
     } catch (Exception $e) {
         Log::error('Could not stamp or save PDF: ' . $pdf->getError());
     }
     $data = ['multipart' => [['name' => $this->document['reference'] . '.pdf', 'contents' => fopen($finalPDF, 'r')]]];
     $httpClient = new HttpClient();
     $httpClient->post(env('CLUSTER_MANAGER') . '/receive-pdf', $data);
     // @todo, use proper Laravel helpers for removing finished-with files
     unlink($dataPDF);
     unlink($finalPDF);
 }
All Usage Examples Of mikehaertl\wkhtmlto\Pdf::addPage