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...
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'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)
Thank you in advance
i want to convert HTML into DOCX so i used \PhpOffice\PhpWord library in laravel
The code for the same is as below
$html = "<html><body><h1>HELLO DEMO</h1></body></html>";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$phpWord->save(public_path('temp/demo.docx'), 'Word2007');
instead of saving the docx, it is showing the HTML on the webpage.
I want to save into a folder
is there anything missed by me, i used this in laravel so require_once "vendor/autoload.php"; might not be required?
You need the
require_once 'vendor/autoload.php';
also add and change
$path = public_path('temp/demo.docx');
$phpWord->save($path, 'Word2007');
I'm trying to create a simple reporting system, which can output either HTML or export to Excel. I have got it to create a HTML table successfully through a Codeigniter view but I want to know if there's any way I can re-use that view to create the Excel export, rather than doing it manually, as I'll then have to update it in two places every time I want to make a change to the report.
Any advice appreciated.
Thanks.
This seems to be working:
// Load the table view into a variable
$html = $this->load->view('table_view', $data, true);
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');
// Delete temporary file
unlink($tmpfile);
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