当我将 docx 转换为 pdf 时,它失去了风格

问题描述 投票:0回答:1

当我将 docx 文件转换为 pdf 文件时,它已转换,但没有样式和阿拉伯字母,它变得像“????”

这是代码:

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');
}

这是文档 AR_6559fe91bb728.docx :

enter image description here

这是 pdf AR_6559fe91bb728.pdf :

enter image description here

pdf docx dompdf laravel-10 docx-to-pdf-conversion
1个回答
0
投票

也许用于打印的CSS媒体查询可以帮助你。

例如:

@media print {
  header, footer, aside, form, … {
    display: none;
  }
  article {
    width:100%!important;
    padding:0!important;
    margin:0!important;
  }
  ...
}
© www.soinside.com 2019 - 2024. All rights reserved.