when i convert docx to pdf its losing the style

103 Views Asked by At

when i convert docx file to pdf file its converted but without style and the arabic letters its becomes like '????'

here is the code :

public function attr(Request $request)
{

   /* Set the PDF Engine Renderer Path */
   $domPdfPath = base_path('vendor/dompdf/dompdf');
   \PhpOffice\PhpWord\Settings::setPdfRendererPath($domPdfPath);
   \PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

   $template = new TemplateProcessor(storage_path('app/public/docs/AR.docx'));

    // Get the form data
    $title = $request->input('title');

    // Replace placeholders with form data
    $template->setValue('title', $title);


    /*@ Save Temporary Word File With New Name */
    $name = uniqid();
    $saveDocPath = storage_path('app/public/docs/AR_'.$name.'.docx');
    $template->saveAs($saveDocPath);

    // Load temporarily create word file
    $Content = \PhpOffice\PhpWord\IOFactory::load($saveDocPath);

    //Save it into PDF
    $savePdfPath = storage_path('app/public/pdfs/attr/AR_'.$name.'.pdf');

     /*@ If already PDF exists then delete it */
     if ( file_exists($savePdfPath) ) {
        unlink($savePdfPath);
    }

    //Save it into PDF
    $PDFWriter = \PhpOffice\PhpWord\IOFactory::createWriter($Content,'PDF');
    $PDFWriter->save($savePdfPath); 
    echo 'File has been successfully converted';

    /*@ Remove temporarily created word file */
    if ( file_exists($saveDocPath) ) {
        unlink($saveDocPath);
    }
    return response()->download($savePdfPath, 'AR.pdf');
}

this is the docx AR_6559fe91bb728.docx :

enter image description here

this is the pdf AR_6559fe91bb728.pdf :

enter image description here

1

There are 1 best solutions below

0
On

Maybe CSS media query for print, can help you.

for example:

@media print {
  header, footer, aside, form, … {
    display: none;
  }
  article {
    width:100%!important;
    padding:0!important;
    margin:0!important;
  }
  ...
}