How to resolve Failed to load PDF document. Error .Iam generating PDF in laravel Using Snappy PDF - wkhtmltopdf

$pdf = App::make('snappy.pdf.wrapper');
$rendered= view('msp.client.campaign-pdf', compact('client', 'batches', 'batch',
'openDevice','sumOfClicked'))->render();
header('Content-Type: application/pdf');
$pdf->setOption('javascript-delay', 800);
echo $pdf->getOutputFromHtml($rendered);
Here is My main controller code where can I create pdf and pass it to view file then echo the output.

Related

Update pdf which is open in laravel

I'm creating pdf file using DOM pdf, it is working but when i try to recreate it with same name and the pdf file is open then i'm getting this error message:
message: exception: "ErrorException" file:
"C:\xampp\htdocs\xxxxxxx\vendor\league\flysystem\src\Adapter\Local.php"
line:
199"file_put_contents(C:\xampp\htdocs\XXXX\storage\app\public/pdf/salary/40_file-2021.pdf):
failed to open stream: Resource temporarily unavailable" trace:
[{function: "handleError", class:
"Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"},…]
$dompdf = new Dompdf();
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->set_option('isRemoteEnabled', true);
$html = view('admin/pdf',['data'=>$data_new])->render();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$fileName = 'pdf/salary/'.$data_new->user_id.'_'.$data_new->application_id.'.pdf';
Storage::put('public/'.$fileName, $dompdf->output());
Any suggestion is highly appreciated.
You need to either:
Close the open PDF before attempting to overwrite it
Write the new PDF to a different location (and probably delete the old PDF after closing it)

Dompdf Class 'Dompdf\Dompdf' not found

Using Dompdf to generate a pdf file. The file is created successfully and downloads but the page I'm running it on generates a fatal error - Class 'Dompdf\Dompdf' not found.
I've downloaded the latest package and uploaded it to the server.
I'm using the quick start code from here - https://github.com/dompdf/dompdf#easy-installation
require_once 'path/to/the/folder/here/dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
I've read all the related support posts I can find but nothing seems to be working
Try this one
<?php
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
This works for me. Just instantiate the dompdf class as follow: $dompdf = new \Dompdf\Dompdf();
<?php
require_once 'path/to/the/folder/here/dompdf/autoload.inc.php';
// Instantiate and use the dompdf class, as follow:
$dompdf = new \Dompdf\Dompdf();
// Then continue your code here...

PHPWORD and TCPDF convert file .DOCX in .PDF

I everybody
i dont have any problem to create .docx fil with PHPWORD
now i want to convert the .docx file created in a .pdf file
im try this simple script but not working on my configuration:
\PhpOffice\PhpWord\Settings::setPdfRendererPath('/PDF/tcpdf.php');
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
//Open template and save it as docx
$document = $phpWord->loadTemplate('edited8.docx');
$document->saveAs('temp.docx');
//Load temp file
$phpWord = \PhpOffice\PhpWord\IOFactory::load('temp.docx');
//Save it
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');
i receive this error
An uncaught Exception was encountered
Type: PhpOffice\PhpWord\Exception\Exception
Message: PDF rendering library or library path has not been defined.
Filename: /application/php_word/vendor/phpoffice/phpword/src/PhpWord/Writer/PDF.php
Line Number: 50
anyone can help me ?
thanks a lot
You need to set Of PDF renderer.
Are you using CodeIgniter? is my code in CodeIgniter:
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = APPPATH.('vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
I'm using DomPDF .. Just Custom a $rendererName and $rendererLibraryPath.
Maybe it's right...

How do I work with zend_pdf in magento?

How do I create a PDF in Magento and write something on it? Here is the sample piece that I have been playing with "on a blank page".
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once($_SERVER['DOCUMENT_ROOT'] . '/app/Mage.php');
Mage::app();
/* --------------------------------------------------------- */
$pdf = new Zend_Pdf('w2.pdf');
$pdf->drawText('sample text', 420,628);
// instruct browser to download the PDF
header("Content-Type: application/x-pdf");
header("Content-Disposition: attachment; filename=w2.pdf");
header("Cache-Control: no-cache, must-revalidate");
// output the PDF
echo $pdf->save('w3.pdf');
But this is the error I'm receiving.
Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'File is not a PDF.' in /Volumes/www/vhosts/magento/lib/Zend/Pdf/Parser.php:396 Stack trace: #0 /Volumes/www/vhosts/magento/lib/Zend/Pdf.php(309): Zend_Pdf_Parser->__construct('w2.pdf', Object(Zend_Pdf_ElementFactory_Proxy), false) #1 /Volumes/www/vhosts/magento/scripts/pdf_gen.php(10): Zend_Pdf->__construct('w2.pdf') #2 {main} thrown in /Volumes/www/vhosts/magento/lib/Zend/Pdf/Parser.php on line 396
The Error doesn't make sense because the w2.pdf is an actual pdf located in the same directory. The w3.pdf file doesnt exist, would this be the problem? Also i changed
$pdf = new Zend_Pdf('w2.pdf');
to
$pdf = new Zend_Pdf();
and received this error
Fatal error: Call to undefined method Zend_Pdf::drawText()
I also tried renaming the w2.pdf to another pdf that i downloaded from the internet including the $pdf->save('file_i_downloaded) and i still get the File is not a PDF error.
This is the PDF I am using: http://www.getharvest.com/resources/invoice-template-pdf
This service here allows you to easily edit your PDF documents.
http://goo.gl/MEA3jT
You can fill out PDF form, save it, fax it, and email it.

PDF generation using dompdf

Using dompdf i generate pdf file. I am successfully generate it .
But after generating it when I open it in Foxit reader it's open very small size in 51.79% mode. When i select 'Fit width' or 125% it show properly.
When I open the pdf by default it open 125% mode can it be possible ?
I used following function:
function pdf_create($html, $filename)
{
ini_set("memory_limit", "50M");
//define pdf store path
$invoice_pdf_path = ABSOLUTE_PATH;
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait");
$dompdf->render();
//$dompdf->stream("abc_out.pdf");
$pdf = $dompdf->output();
#file_put_contents($invoice_pdf_path . $filename . ".pdf", $pdf);
}
With dompdf 0.6 beta you can set the default view of the PDF by adding a meta tag in your HTML source code:
<meta name="dompdf.view" content="FitH" />
Possible values are "XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "FitBH", "FitBV", described here

Resources