PHP mPDF save file as PDF

前端 未结 4 1162
难免孤独
难免孤独 2020-12-23 20:44

I have a page which uses mPDF which when you run displays a PDF in the browser, it can also be saved from here as a PDF no problem. What I would like to happen is when the p

相关标签:
4条回答
  • 2020-12-23 20:53

    This can be done like this. It worked fine for me. And also set the directory permissions to 777 or 775 if not set.

    ob_clean();
    $mpdf->Output('directory_name/pdf_file_name.pdf', 'F');
    
    0 讨论(0)
  • 2020-12-23 20:54

    The Go trough this link state that the first argument of Output() is the file path, second is the saving mode - you need to set it to 'F'.

     $upload_dir = public_path(); 
                 $filename = $upload_dir.'/testing7.pdf'; 
                  $mpdf = new \Mpdf\Mpdf();
                  //$test = $mpdf->Image($pro_image, 0, 0, 50, 50);
    
                  $html ='<h1> Project Heading </h1>';
                  $mail = ' <p> Project Heading </p> ';
                  
                  $mpdf->autoScriptToLang = true;
                  $mpdf->autoLangToFont = true;
                  $mpdf->WriteHTML($mail);
    
                  $mpdf->Output($filename,'F'); 
                  $mpdf->debug = true;
    

    Example :

     $mpdf->Output($filename,'F');
    

    Example #2

    $mpdf = new \Mpdf\Mpdf();
    $mpdf->WriteHTML('Hello World');
    
    // Saves file on the server as 'filename.pdf'
    $mpdf->Output('filename.pdf', \Mpdf\Output\Destination::FILE);
    
    0 讨论(0)
  • 2020-12-23 21:00

    Try this:

    $mpdf->Output('my_filename.pdf','D'); 
    

    because:

    D - means Download
    F - means File-save only

    0 讨论(0)
  • 2020-12-23 21:15

    The mPDF docs state that the first argument of Output() is the file path, second is the saving mode - you need to set it to 'F'.

    $mpdf->Output('filename.pdf','F');
    
    0 讨论(0)
提交回复
热议问题