0

I'm using fpdf to generate my invoice.

so the problem is whenever I open the link the file downloading automatically ..

I want to print the file when I click on the link...

I have tried onclick="print();"

but its printing the HTML page

the link :

echo "<th><a href='invoices.php?source=print_invoice&inv_id=$inv_id'>print</a></th>";

I also tried using I in $pdf->Output('invoice.pdf','I');

not working also ...

edit :

I tried this Script But is not working

I get these two errors :

Notice: Constant FPDF_VERSION already defined

Fatal error: Cannot redeclare class FPDF

Is it possible to display the print dialog with the pdf from the link when I click the print?

Alan GE
  • 1
  • 3
  • Possible duplicate of [Can a PDF file's print dialog be opened with Javascript?](https://stackoverflow.com/questions/687675/can-a-pdf-files-print-dialog-be-opened-with-javascript) – gre_gor Mar 26 '18 at 21:16

1 Answers1

1

I had this problem at my job. My solution was to open a new window with print options and attach the html content.

your html

<button type="button" onclick="foo();">Click to print </button>

Your javascript

function foo(){
$.get( 'your_server_pdf_generator.php', {anyvariable: "value" },  function 
(returnedHtml) 
  {
        var mywindow = window.open('', 'PRINT', 'height=400,width=600');
        mywindow.document.write(returnedHtml);
        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10*/
        mywindow.print();
        mywindow.close();
        return true;} );}
divibisan
  • 11,659
  • 11
  • 40
  • 58
Carlos Montiel
  • 301
  • 1
  • 4
  • 16