Tcpdf pdf文件无法下载

时间:2015-11-28 21:34:29

标签: php tcpdf

当我点击使用TCPDF api的链接时。此链接打开新选项卡打开,下载链接显示但文件大小未显示。并且没有下载文件。

class MYPDF extends TCPDF {

public function Header() {

$image_file = 'images/logo.png';
$this->Image($image_file, 10, 10, null, null, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('', 'B', 20);
$this->Cell(0, 15, 'Global Tours Center', 0, false, 'C', 0, '', 0, false, 'M', 'M');

}
public function Footer() {

$this->SetY(-15);
$this->SetFont('', 'I', 8);
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');

}

}
ob_clean();
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Hamaad');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {

require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);

}
$pdf->AddPage();
$pdf->SetFont('times', '', 10);
$html = "here is my html code";
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
error_reporting(E_ALL);
$pdf->Output('ticket.pdf', 'I');

请指导我,我坚持这一点。该怎么办。

enter image description here

1 个答案:

答案 0 :(得分:0)

我运行此代码,它与我合作: 首先,您应该包含文件includes / tcpdf / tcpdf.php 其次,您应该确定徽标图像文件已经存在:$ image_file ='images / logo.png';

此代码与我一起运行:

<?php
require_once("../include.inc.php");
require_once (MAIN_DOCUMENT_ROOT . "/includes/tcpdf/config/lang/ara.php");
require_once (MAIN_DOCUMENT_ROOT . "/includes/tcpdf/tcpdf.php");

class MYPDF extends TCPDF {

public function Header() {

//$image_file = 'images/logo.png';
//$this->Image($image_file, 10, 10, null, null, 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('', 'B', 20);
$this->Cell(0, 15, 'Global Tours Center', 0, false, 'C', 0, '', 0, false, 'M', 'M');

}
public function Footer() {

$this->SetY(-15);
$this->SetFont('', 'I', 8);
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');

}

}
ob_clean();
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Hamaad');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {

require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);

}
$pdf->AddPage();
$pdf->SetFont('times', '', 10);
$html = "here is my html code";
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
error_reporting(E_ALL);
$pdf->Output('ticket.pdf', 'I');