doujia4759 2018-03-26 21:09
浏览 56

打印生成的pdf文件

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?

  • 写回答

1条回答 默认 最新

  • dselp3944 2018-09-05 15:38
    关注

    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;} );}
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算