Tcpdf pdf 文件无法下载
Tcpdf pdf file does not download
当我点击 link 时,其中使用了 TCPDF api。此 link 打开新选项卡并显示下载 link 但不显示文件大小。并且没有下载文件。
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');
请指导我,我坚持这一点。怎么办怎么办。
我运行这段代码,它适用于我:
首先,您应该包含文件 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');
当我点击 link 时,其中使用了 TCPDF api。此 link 打开新选项卡并显示下载 link 但不显示文件大小。并且没有下载文件。
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');
请指导我,我坚持这一点。怎么办怎么办。
我运行这段代码,它适用于我: 首先,您应该包含文件 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');