stamp() public method

The $file should have a transparent background.
public stamp ( string $file ) : Pdf
$file string name of the PDF file to add as overlay. Only the first page is used.
return Pdf the pdf instance for method chaining
 /**
  * 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);
 }
Esempio n. 2
0
 public function testCanStamp()
 {
     $document1 = $this->getDocument1();
     $document2 = $this->getDocument2();
     $file = $this->getOutFile();
     $pdf = new Pdf($document1);
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->stamp($document2));
     $this->assertTrue($pdf->saveAs($file));
     $this->assertFileExists($file);
     $tmpFile = (string) $pdf->getTmpFile();
     $this->assertEquals("pdftk A='{$document1}' stamp '{$document2}' output '{$tmpFile}'", (string) $pdf->getCommand());
 }