php TCPDF 输出而不保存文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4708623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 14:04:59  来源:igfitidea点击:

TCPDF output without saving file

phppdftcpdf

提问by Mirgorod

How to use TCPDF to output pdf file in browser without saving like in ezpdf?

如何使用TCPDF在浏览器中输出pdf文件而不像ezpdf那样保存?

回答by Alec

Use Ifor "inline" to send the PDF to the browser, opposed to Fto save it as a file.

使用I的“内联”的PDF发送到浏览器,而不是F将其保存为一个文件。

$pdf->Output('name.pdf', 'I');

$pdf->Output('name.pdf', 'I');

回答by Baach

This is what I found out in the documentation.

这是我在文档中发现的。

  • I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
  • D: send to the browser and force a file download with the name given by name.
  • F: save to a local server file with the name given by name.
  • S: return the document as a string (name is ignored).
  • FI: equivalent to F + I option
  • FD: equivalent to F + D option
  • E: return the document as base64 mime multi-part email attachment (RFC 2045)
  • I:将文件内联发送到浏览器(默认)。如果可用,则使用插件。当在生成 PDF 的链接上选择“另存为”选项时,将使用名称给出的名称。
  • D: 发送到浏览器并使用 name 给出的名称强制下载文件。
  • F: 使用 name 指定的名称保存到本地服务器文件。
  • S:以字符串形式返回文档(名称被忽略)。
  • FI: 相当于 F + I 选项
  • FD: 相当于 F + D 选项
  • E: 将文档作为 base64 mime 多部分电子邮件附件 (RFC 2045) 返回

回答by Line

If You want to open dialogue window in browser to save, not open with PDF browser viewer (I was looking for this solution for a while), You should use 'D':

如果您想在浏览器中打开对话窗口进行保存,而不是使用 PDF 浏览器查看器打开(我一直在寻找这个解决方案),您应该使用“D”:

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

回答by Chris Hasiński

Print the PDF header (using header() function) like: header("Content-type: application/pdf");

打印 PDF 标题(使用 header() 函数),如: header("Content-type: application/pdf");

and then just echo the content of the PDF file you created (instead of writing it to disk).

然后只回显您创建的 PDF 文件的内容(而不是将其写入磁盘)。

回答by siltendo

Hint - with a saving file:

提示 - 带有保存文件:

$pdf->Output('sandbox/pdf/example.pdf', 'F');

回答by Djonatan

I've been using the Output("doc.pdf", "I");and it doesn't work, I'm always asked for saving the file.

我一直在使用它Output("doc.pdf", "I");,但它不起作用,总是要求我保存文件。

I took a look in documentation and found that

我查看了文档,发现

I send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF. http://www.tcpdf.org/doc/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

我将文件内联发送到浏览器(默认)。如果可用,则使用插件。当在生成 PDF 的链接上选择“另存为”选项时,将使用名称给出的名称。 http://www.tcpdf.org/doc/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

Then I think you have to use a plugin to print it, otherwise it is going to be downloaded.

那我觉得你得用插件打印出来,不然要下载了。

回答by Guppy

It works with Ifor inline as stated, but also with O.

I如上所述,它适用于内联,但也适用于O.

$pdf->Output('name.pdf', 'O');

It is perhaps easier to remember (Ofor Open).

可能更容易记住(O对于 Open)。

回答by Nilesh Prajapati

      $filename= time()."pdf"; 
    //$filelocation = "C://xampp/htdocs/Nilesh/Projects/mkGroup/admin/PDF";

     $filelocation = "/pdf uplaod path/";
     $fileNL = $filelocation."/".$filename;

       $pdf->Output($fileNL,'F');
       $pdf->Output($filename, 'S');