Category : phpword

I’m using Laravel 8 and want to use PHPWord This is my controller <?php namespace AppHttpControllers; use Exception; use IlluminateHttpRequest; use IlluminateSupportFacadesDB; use IlluminateSupportFacadesResponse; class CWord extends Controller{ public function CreateWord() { $desc1 = DB::table(‘dummy’)->where(‘id’,1)->first(); $path = "assets_file/"; $my_template = new PhpOfficePhpWordTemplateProcessor(public_path($path.’helloWorld.docx’)); $my_template->setValue(‘name’, $desc1->content); try{ $my_template->saveAs(public_path($path.’user_1.docx’)); }catch (Exception $e){ //handle exception } return response()->download(public_path($path.’user_1.docx’)); } ..

Read more

After many tries and and researches, I still can’t get the header and footer of my docx file after the conversion to PDF. I read many topics and looked at the issue on the github forum but didn’t find what I needed. I also tried with TCPDF and same result. $domPdfPath = base_path(‘vendor/dompdf/dompdf’); Settings::setPdfRendererPath($domPdfPath); Settings::setPdfRendererName(‘DomPDF’); ..

Read more

I am trying to change the alignment of the image added into the docx file, but the alignment is not working. I have tried as below: $templateProcessor->setImageValue($tag->template_tag, array( ‘path’ => $filePath, ‘positioning’ => PhpOfficePhpWordStyleImage::POSITION_ABSOLUTE, ‘alignment’ => PhpOfficePhpWordSimpleTypeJc::END, ) ); Though the image is rendered in exported docx file, however the image alignment is always left. ..

Read more

I’m trying to download a word document from storage path using Laravel8 and Ajax call. So I’m using the following code : <script> $(document).on(‘click’, ‘.download’, function(){ var data = ”; var id = $(this).attr(‘id’); console.log(id); var data=”; $.ajax({ url:"modeles_contrat/"+id+"/download", type:"GET", data: data, xhrFields: { responseType: ‘blob’ }, success: function(response){ var blob = new Blob([response]); var ..

Read more

I would like to convert a complex word doc into PDF but face the following issues. If anyone has any suggestions or alternatives to phpword. Existing word doc has multiple pages with different styles and formattings. I tried using phpword to replace variables with data, but unable to add html tags/code, E.g. <ul><li>code</li><ul>, this turns ..

Read more

So I want to add an header image to my document in PHPWord in Laravel. So this is my code public function generateDocx() { $phpWord = new PhpOfficePhpWordPhpWord(); $section = $phpWord->addSection(); $headerLogo = ‘http://127.0.0.1:8000/img/logoAnevBulanan.png’; $section->addImage($headerLogo); // Bunch of line to download the docx } And I got Maximum execution time of 60 seconds exceeded, when ..

Read more

I’m trying to work with PhpWord library for generating a Word files using Laravel. I search for the documentation of this library and how it worked, I found that I should have already a template to work with. But In my case I should create this template from database and then generate this file on ..

Read more

I am using "phpoffice/phpword": "^0.18.2" with "php": "^7.3|^8.0" to replace particular contents of docx file. I have tried the following code to replace and download the contents of docx file. $file = public_path(‘assets/dist/sample.docx’); $phpword = new PhpOfficePhpWordTemplateProcessor($file); $phpword->setValue(‘firstname’, ‘John Doe’); $phpword->setValue(‘shareholderNumber’, ‘5’); $phpword->setValue(‘address’, ‘Newyork’); header("Content-Description: File Transfer"); header(‘Content-Disposition: attachment; filename=test.docx’); header(‘Content-Type: application/docx’); header(‘Content-Transfer-Encoding: binary’); header(‘Cache-Control: ..

Read more

I wan´t to convert a .docx file into PDF. If I use The PhpOfficePhpWord Libraries, i lose my styles, so i have tried with OfficeConverter, but i have this error: "Convertion Failure! Contact Server Admin." I have this in my Controller $converter = new OfficeConverter(storage_path(‘./../MyFile.docx’)); $converter->convertTo(storage_path(‘./../MyFile.pdf’)); Also in the header of this php file i ..

Read more

I have a problem. I try genrate .docx file to .pdf file with Laravel library "mPDF" and got this error: My code on controller: $domPdfPath = base_path(‘vendor/mpdf/mpdf’); PhpOfficePhpWordSettings::setPdfRendererPath($domPdfPath); PhpOfficePhpWordSettings::setPdfRendererName(‘mPDF’); //Load word file $Content = PhpOfficePhpWordIOFactory::load(public_path( ‘/uploads/word/no12.docx’)); //Save it into PDF $PDFWriter = PhpOfficePhpWordIOFactory::createWriter($Content,’PDF’); $PDFWriter->save(public_path( ‘/uploads/word/result3.pdf’)); dd($PDFWriter); And error: PDF rendering library or library path has ..

Read more

I made the following controller that fills a docx document with values. namespace AppControllersServices; use AppControllersBaseController; use IlluminateSupportFacadesResponse; use PhpOfficePhpWordTemplateProcessor; use PhpOfficePhpWordPhpWord; class Contract extends BaseController { public function getContract() { $file = storage_path()."/contracts/contract.docx"; $tmpFile = storage_path()."/contracts/output.docx"; $template = new TemplateProcessor($file); $template->setValue(‘COMP_NAME’,"LOREM IPSUM INC"); $template->setValue(‘ADDRESS’,"Nowhere Str Tsastikistan"); $template->saveAs($tmpFile); return Response::make("OK"); } } I want the ..

Read more