在magento中使用tcpdf创建pdf [英] create a pdf with tcpdf in magento

查看:44
本文介绍了在magento中使用tcpdf创建pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用magento中的TCPDF创建pdf,我需要导入图像或pdf并对其进行修改.我在firefox中使用的代码效果很好,但在chrome或Internet中却无法使用.

I'm trying to create a pdf with TCPDF in magento, i need to import a image or a pdf and modify it. my code in firefox works good but doesn't work in chrome or in internet.

我放了一些代码:

我的控制器:

  public function printAction()
{
    if (($cardCode = $this->getRequest()->getParam('code'))) {
        $this->loadLayout('print');

        $this->getResponse()->clearHeaders()
                            ->setHeader('Content-Type', 'application/pdf');
        $this->renderLayout();
    } else {
        $this->_redirect('/');
    }
}

我的phtml:

require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8',       false);
$pdf->SetFont('helvetica', '', 15);

$pdf->AddPage();

$pdf->setJPEGQuality(100);
$fileName = Mage::getConfig()->getOptions()->getMediaDir()."/pdf/Gutschein-v2.jpg";

$pdf->Image($fileName, 0, 0, 210, 266, 'JPG', '', '', true, 150, '', false, false, 1,  false, false, false);

if ($giftCard->getMailTo()) { 
$name = $this->helper('core')->escapeHtml($giftCard->getMailTo(), null);
}
if ($giftCard->getMailFrom()) { 
$from = $this->helper('core')->escapeHtml($giftCard->getMailFrom(), null);
}
$code=$giftCard->getCardCode();
$currency= Mage::helper('core')->currency($giftCard->getCardAmount(), true, false);

$pdf->MultiCell(80, 5, $name."\n", 1, 'J', 1, 1, 60, 102, true);
$pdf->MultiCell(80, 5, $from."\n", 1, 'J', 1, 1, 60, 123, true);
$pdf->MultiCell(80, 5, $currency."\n", 1, 'J', 1, 1, 60, 145, true);
$pdf->MultiCell(80, 5, $code."\n", 1, 'J', 1, 1, 60, 166, true);

$pdf->lastPage();
ob_start();
$pdf->Output('example_009.pdf', 'I');
ob_end_flush();

我可以在Firefox中完美地看到pdf,但是无法从计算机上下载并打开它. 错误:pdf文件损坏.

I can see the pdf perfectly in firefox but not download and open it from my computer. Error: pdf ist damaged.

在Internet和Google Chrome浏览器中,我看不到pdf.

In internet and google chrome i can't see the pdf.

我不知道我做错了什么. 谢谢.

I don't know waht i'm doing wrong. thank you.

推荐答案

您可以按照以下步骤轻松地在magento中添加tcpdf.

you can easily add tcpdf in magento by following steps.

步骤1:此处

步骤2:在magento根目录下的magento的lib目录中创建目录 TCPDF (路径类似于/lib/TCPDF). (如果没有创建目录的权限,请从cPanel创建目录)

Step 2: Create a directory TCPDF in magento’s lib directory in magento root (path like /lib/TCPDF). (if not permission to create directory then create it from cPanel)

步骤3: tcpdf.php 复制到目录&将 tcpdf.php 重命名为 TCPDF.php

Step 3: Copy tcpdf.php in directory & rename tcpdf.php to TCPDF.php

步骤4::复制 tcpdf_autoconfig.php 文件.同时复制字体&打开TCPDF.php并将类名称更改为类TCPDF_TCPDF {文件夹

Step 4: Copy tcpdf_autoconfig.php file. Also copy fonts & open TCPDF.php and change class name to class TCPDF_TCPDF { folder

步骤5::打开 TCPDF.php ,并将类名称更改为 class TCPDF_TCPDF {

Step 5: Open TCPDF.php and change class name to class TCPDF_TCPDF {

第6步:使用以下示例代码进行测试:

Step 6: Use the below sample code for testing:

$tcpdf = new TCPDF_TCPDF();

//your htmls here
$html = '<h1> hello world </h1>';

$tcpdf->AddPage();

$tcpdf->writeHTML($html, true, false, true, false, '');

$tcpdf->lastPage();

$tcpdf->Output('report_per_route_'.time().'.pdf', 'I');

或将pdf文件保存在var/report

$fn = Mage::getBaseDir('base').'/var/report/report_'.time().'.pdf';
$tcpdf->Output($fn, 'F');

这篇关于在magento中使用tcpdf创建pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆