3

I am using TCPDF library to generate some reports, and i want to send the PDF file to print option of browser as simple we press CTRL+P, I need this because it is slip. I used all parameter for Output but it is downloading the file directly.

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

I also placed the F,D,S,E,FI and FD instate of I but it doesn't work. And I also used header

header('Content-Type: application/pdf');
$pdf->Output('example_001.pdf', 'FD');

but again it doesn't work. Any solution? Please!

Serjik
  • 10,543
  • 8
  • 61
  • 70
Ali
  • 387
  • 1
  • 7
  • 25

4 Answers4

10

Add $pdf->IncludeJS("print();"); just before $pdf->Output...

Radovan
  • 109
  • 1
  • 2
4

You need something like the example below. You would need to intercept print request (print automatically on page load, print button click, etc.) and then call printTrigger function.

<html>
<head>
    <title>Print PDF</title>
    <script>
        function printTrigger(elementId) {
            var getMyFrame = document.getElementById(elementId);
            getMyFrame.focus();
            getMyFrame.contentWindow.print();
        }
    </script>
</head>

<body>
    <iframe id="iFramePdf" src="http://pdfurl.com/sample.pdf"></iframe>
...
</body>
</html>
apat
  • 66
  • 5
1

What you are trying to do is not within the specification of the TCPDF API.

http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

I believe you would need to use JavaScript to implement this feature the way you are proposing.

JamesG
  • 4,288
  • 2
  • 31
  • 36
-2

Add $pdf->IncludeJS("print();"); just before $pdf->Output... It's working for me.