getError() public method

public getError ( ) : string
return string the detailed error message. Empty string if none.
 /**
  * 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);
 }
示例#2
0
 * Send some HTML source to this endpoint and it will convert it to
 * a PDF file
 * It returns a unique ID as result
 */
$app->post('/api/generate/', function (Request $request) {
    // save html source to local document
    $source = $request->getContent();
    $sourceFile = getFile(Uuid::uuid4()->toString(), 'html');
    file_put_contents($sourceFile, $source);
    // generate destination PDF file
    $id = Uuid::uuid4()->toString();
    $destination = getFile($id, 'pdf');
    // create PDF file
    $pdf = new Pdf($sourceFile);
    if (!$pdf->saveAs($destination)) {
        return error($pdf->getError());
    } else {
        return new JsonResponse(['id' => $id]);
    }
});
/**
 * Download PDF
 * Use the ID that was returned in the `generate` endpoint to download the file
 * using this endpoint
 */
$app->get('/api/download/{id}', function ($id) {
    $file = getFile($id, 'pdf');
    // make sure the file exists
    if (!file_exists($file)) {
        return error("file with is '{$id}' is not found");
    }
示例#3
0
require 'vendor/autoload.php';
use mikehaertl\wkhtmlto\Pdf;
// http://localhost:8000/invoice.php?invoice_id=INV2674984&customer_id=CUST1589
//Data Retreival/////Ek sal hier n query op die DB doen
$customer_id = $_GET["customer_id"];
$invoice_id = $_GET["invoice_id"];
$email_to = "*****@*****.**";
$email_from = "*****@*****.**";
$file_path = 'tmp/' . $invoice_id . '_' . $customer_id . '.pdf';
// Generate HTML and convert to PDF
$pdf = new Pdf();
$pdf->addPage("<html>" . "<body>" . "<div>Invoice " . $invoice_id . "<div>From" . "<div class='detail'>From Name</div>" . "<div class='detail'>From Details</div>" . "<div class='detail'>From Address</div>" . "</div>" . "<div>To" . "<div class='detail'>email</div>" . "<div class='detail'>contact number</div>" . "<div class='detail'>physical address</div>" . "<div class='detail'>medical aid</div>" . "<div class='detail'>number and main memmber</div>" . "<div class='detail'>ID number</div>" . "</div>" . "<table>Items" . "<tr>" . "<th class='detail'>Description</th>" . "<th class='detail'>Quantity</th>" . "<th class='detail'>Price</th>" . "<th class='detail'>Total</th" . "</tr>" . "<tr>" . "<td>Test item</td>" . "<td>2</td>" . "<td>10</td>" . "<td>20</td>" . "</tr>" . "<tr>" . "<td>Test item 2</td>" . "<td>2</td>" . "<td>20</td>" . "<td>40</td>" . "</tr>" . "</table>" . "<div>Message" . "<div class='detail'>Footer van die Invoice</div>" . "</div>" . "</div>" . "</body>" . "</html>");
// Save the pdf to the temp directory
if (!$pdf->saveAs($file_path)) {
    // an error has occurred notify the user
    echo $pdf->getError();
    die;
} else {
    // The pdf has successfully been created, send the email with the pdf attached
    $sendgrid = new SendGrid('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');
    $email = new SendGrid\Email();
    $email->addTo($email_to)->setFrom($email_from)->setSubject('Invoice: ' . $invoice_id . ' for customer: ' . $customer_id)->setText('Hi, Please find attached your requested invoice.')->setHtml('Hi, <br /><br />Please find attached your requested invoice.')->addAttachment($file_path);
    try {
        // Send the email
        $sendgrid->send($email);
        // Delete the pdf from the tmp dir
        unlink($file_path);
    } catch (\SendGrid\Exception $e) {
        // The email could not be sent, notify the user
        echo $e->getCode();
        foreach ($e->getErrors() as $er) {
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function getError()
 {
     return $this->pdf->getError();
 }