Reputation: 1
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?
Upvotes: 0
Views: 2127
Reputation: 301
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;} );}
Upvotes: 1