PDF不能使用artkonekt下载

时间:2018-05-06 20:21:04

标签: php pdf download pdf-generation

我正在尝试使用artkonekt库。 我使用以下代码成功使用该示例:

require_once(APPPATH . '/third_party/vendor/autoload.php');
use Konekt\PdfInvoice\InvoicePrinter as Printer;
...
    public function createInvoice()
        {
            $invoice = new Printer();
            $imgurl = base_url() . MODULES_IMAGES . 'contact_volunteer_module.jpg';
            $invoice->setLogo($imgurl);   //logo image path
            $invoice->setColor("#007fff");      // pdf color scheme
            $invoice->setType("Sale Invoice");    // Invoice Type
            $invoice->setReference("INV-55033645");   // Reference
            $invoice->setDate(date('M dS ,Y',time()));   //Billing Date
            $invoice->setTime(date('h:i:s A',time()));   //Billing Time
            $invoice->setDue(date('M dS ,Y',strtotime('+3 months')));    // Due Date
            $invoice->setFrom(array("Seller Name","Sample Company Name","128 AA Juanita Ave","Glendora , CA 91740"));
            $invoice->setTo(array("Purchaser Name","Sample Company Name","128 AA Juanita Ave","Glendora , CA 91740"));

            $invoice->addItem("AMD Athlon X2DC-7450","2.4GHz/1GB/160GB/SMP-DVD/VB",6,0,580,0,3480);
            $invoice->addItem("PDC-E5300","2.6GHz/1GB/320GB/SMP-DVD/FDD/VB",4,0,645,0,2580);
            $invoice->addItem('LG 18.5" WLCD',"",10,0,230,0,2300);
            $invoice->addItem("HP LaserJet 5200","",1,0,1100,0,1100);

            $invoice->addTotal("Total",9460);
            $invoice->addTotal("VAT 21%",1986.6);
            $invoice->addTotal("Total due",11446.6,true);

            $invoice->addBadge("Payment Paid");

            $invoice->addTitle("Important Notice");

            $invoice->addParagraph("No item will be replaced or refunded if you don't have the invoice with you.");

            $invoice->setFooternote("My Company Name Here");

            $invoice->render('example1123.pdf','D');

            //var_dump($invoice);
        }

如果我然后加载页面,我看到的只是一个空白页面,没有创建PDF。 当var_dumping $ invoice时,我可以看到创建了数组并且填写了所有字段。还有什么我需要做的才能让文件下载吗?

1 个答案:

答案 0 :(得分:0)

经过一番挖掘后,我发现问题出在FPDF类中。

ob_clean();放在输出类中为我解决了这个问题。

此解决方案来自以下主题: FPDF error: Some data has already been output, can't send PDF