TCPDF Save file to folder?

后端 未结 11 1981
耶瑟儿~
耶瑟儿~ 2020-12-13 07:05

I\'m using TCPDF to print a receipt and then send it to customer with phpMailer, but I have a problem:

I have no idea how to save the file into a pdf.

相关标签:
11条回答
  • 2020-12-13 07:15

    If you still get

    TCPDF ERROR: Unable to create output file: myfile.pdf

    you can avoid TCPDF's file saving logic by putting PDF data to a variable and saving this string to a file:

    $pdf_string = $pdf->Output('pseudo.pdf', 'S');
    file_put_contents('./mydir/myfile.pdf', $pdf_string);
    
    0 讨论(0)
  • 2020-12-13 07:16

    nick's example saves it to your localhost.
    But you can also save it to your local drive.
    if you use doublebackslashes:

     $filename= "Invoice.pdf"; 
     $filelocation = "C:\\invoices";  
    
     $fileNL = $filelocation."\\".$filename;
     $pdf->Output($fileNL,'F');
    
     $pdf->Output($filename,'D'); // you cannot add file location here
    

    P.S. In Firefox (optional) Tools> Options > General tab> Download >Always ask me where to save files

    0 讨论(0)
  • 2020-12-13 07:17

    try this

    $pdf->Output('kuitti'.$ordernumber.'.pdf', 'F');
    
    0 讨论(0)
  • 2020-12-13 07:21

    TCPDF uses fopen() to save files. Any paths passed to TCPDF's Output() function should thus be an absolute path.

    If you would like to save to a relative path, use e.g. the __DIR__ global constant (see this answer).

    0 讨论(0)
  • 2020-12-13 07:27

    For who is having difficulties storing the file, the path has to be all the way through root. For example, mine was:

    $pdf->Output('/home/username/public_html/app/admin/pdfs/filename.pdf', 'F');
    
    0 讨论(0)
  • 2020-12-13 07:28

    Only thing that worked for me:

    // save file
    $pdf->Output(__DIR__ . '/example_001.pdf', 'F');
    exit();
    
    0 讨论(0)
提交回复
热议问题