2016-11-21 37 views
0

我正在将php转换为pdf与phptopdf,我成功地生成了该库的pdf文件,但在生成PDF之后,它不能运行任何PDF阅读器,包括除Mozilla Firefox之外的任何浏览器。phptopdf.php生成pdf不起作用

只生成PDF工作FF,但我需要工作至少任何PDF阅读器。我也试过在线PDF阅读器,但那也不起作用。

我试过这个http://phptopdf.com/examples/#generate_pdf_invoice片断来生成PDF和简单的但没有工作。

奇怪的事情如何生成PDF工作只Mozilla Firefox为什么不是其他 其他?

<?php 
// INCLUDE THE phpToPDF.php FILE 
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE 
$my_html="<html lang=\"en\"> 
    <head> 
    <meta charset=\"UTF-8\"> 
    <title>Sample Invoice</title> 
    <link rel=\"stylesheet\" href=\"http://phptopdf.com/bootstrap.css\"> 
    <style> 
     @import url(http://fonts.googleapis.com/css?family=Bree+Serif); 
     body, h1, h2, h3, h4, h5, h6{ 
     font-family: 'Bree Serif', serif; 
     } 
    </style> 
    </head> 

    <body> 
    <div class=\"container\"> 
     <div class=\"row\"> 
     <div class=\"col-xs-6\"> 
      <h1> 
      <a href=\"http://phptopdf.com\">    
      Logo here 
      </a> 
      </h1> 
     </div> 
     <div class=\"col-xs-6 text-right\"> 
      <h1>INVOICE</h1> 
      <h1><small>Invoice #001</small></h1> 
     </div> 
     </div> 
     <div class=\"row\"> 
     <div class=\"col-xs-5\"> 
      <div class=\"panel panel-default\"> 
      <div class=\"panel-heading\"> 
       <h4>From: <a href=\"#\">Your Name</a></h4> 
      </div> 
      <div class=\"panel-body\"> 
       <p> 
       Address <br> 
       details <br> 
       more <br> 
       </p> 
      </div> 
      </div> 
     </div> 
     <div class=\"col-xs-5 col-xs-offset-2 text-right\"> 
      <div class=\"panel panel-default\"> 
      <div class=\"panel-heading\"> 
       <h4>To : <a href=\"#\">Client Name</a></h4> 
      </div> 
      <div class=\"panel-body\"> 
       <p> 
       Address <br> 
       details <br> 
       more <br> 
       </p> 
      </div> 
      </div> 
     </div> 
     </div> 
     <!--/end client details section --> 
     <table class=\"table table-bordered\"> 
     <thead> 
      <tr> 
      <th> 
       <h4>Service</h4> 
      </th> 
      <th> 
       <h4>Description</h4> 
      </th> 
      <th> 
       <h4>Hrs/Qty</h4> 
      </th> 
      <th> 
       <h4>Rate/Price</h4> 
      </th> 
      <th> 
       <h4>Sub Total</h4> 
      </th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
      <td>Article</td> 
      <td><a href=\"#\">Title of your article here</a></td> 
      <td class=\"text-right\">-</td> 
      <td class=\"text-right\">$200.00</td> 
      <td class=\"text-right\">$200.00</td> 
      </tr> 
      <tr> 
      <td>Template Design</td> 
      <td><a href=\"#\">Details of project here</a></td> 
      <td class=\"text-right\">10</td> 
      <td class=\"text-right\">75.00</td> 
      <td class=\"text-right\">$750.00</td> 
      </tr> 
      <tr> 
      <td>Development</td> 
      <td><a href=\"#\">WordPress Blogging theme</a></td> 
      <td class=\"text-right\">5</td> 
      <td class=\"text-right\">50.00</td> 
      <td class=\"text-right\">$250.00</td> 
      </tr> 
     </tbody> 
     </table> 
     <div class=\"row text-right\"> 
     <div class=\"col-xs-2 col-xs-offset-8\"> 
      <p> 
      <strong> 
      Sub Total : <br> 
      TAX : <br> 
      Total : <br> 
      </strong> 
      </p> 
     </div> 
     <div class=\"col-xs-2\"> 
      <strong> 
      $1200.00 <br> 
      N/A <br> 
      $1200.00 <br> 
      </strong> 
     </div> 
     </div> 
     <div class=\"row\"> 
     <div class=\"col-xs-5\"> 
      <div class=\"panel panel-info\"> 
      <div class=\"panel-heading\"> 
       <h4>Bank details</h4> 
      </div> 
      <div class=\"panel-body\"> 
       <p>Your Name</p> 
       <p>Bank Name</p> 
       <p>SWIFT : --------</p> 
       <p>Account Number : --------</p> 
       <p>IBAN : --------</p> 
      </div> 
      </div> 
     </div> 
     <div class=\"col-xs-7\"> 
      <div class=\"span7\"> 
      <div class=\"panel panel-info\"> 
       <div class=\"panel-heading\"> 
       <h4>Contact Details</h4> 
       </div> 
       <div class=\"panel-body\"> 
       <p> 
        Email : [email protected] <br><br> 
        Mobile : -------- <br><br><br> 
       </p> 
       <h4>Payment should be made by Bank Transfer</h4> 
       </div> 
      </div> 
      </div> 
     </div> 
     </div> 
     <br><br> 
     This is a sample invoice.<br><br> 
     In this example the css style is pulled from phptopdf.com/bootstrap.css 
     You could also put all CSS in the header wrapped in <xmp> <style> </xmp> tags 
    </div> 
    </body> 
</html>"; 

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE: http://phptopdf.com/documentation/ 
$pdf_options = array(
    "source_type" => 'html', 
    "source" => $my_html, 
    "action" => 'download', 
    "file_name" => 'pdf_invoice.pdf'); 

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE 
phptopdf($pdf_options); 

?> 

任何帮助将升值。

回答

0

谢谢你们,我解决我的问题。

这是我找到工作的两种方式。

  1. 期运用外部PHP作为一种形式的行动,那么表格后,提交它的工作不错,但同一个页面上,如果我作为动作链接无法正常工作。

  2. 更好的方法是先将您的服务器上的pdf先保存到您的服务器上,然后取出链接,然后用该链接下载。

例如:

$pdf_options = array(
    "source_type" => 'html', 
    "source" => $my_html, 
    "action" => 'save', 
    "save_directory" => 'wp-content/uploads/invoices/', 
    "file_name" => $current_user->ID . '-' .$invoice['invoice_id'] . '.pdf'); 

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE 
phptopdf($pdf_options); 
0

为什么不使用DomPDF?我将它用于我的所有项目。没有问题..

https://github.com/dompdf/dompdf

+0

谢谢你的提示,我之前已经使用的那一个,那一个不是要去这里解决我的问题,你看你不能让欲望MARUP和CSS与DOMPDF PDF 。这是支持有限的CSS。 – mlbd