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)
Related
$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.
I am trying to use dompdf here to convert html to PDF, initial it works perfectly but I tried checking the link now and I got 406 Not Acceptable error. I am not sure where I got it wrong but any help will be appreciated, find below the code:
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';
$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
//$dompdf = new Dompdf();
$dompdf->loadHtml('Hello world');
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
exit(0);
And I'm using the library from this link https://github.com/nFnK/dompdf
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 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.
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