【问题标题】:TCPDF is not downloadingTCPDF 未下载
【发布时间】:2018-12-05 04:21:12
【问题描述】:

我使用 TCPDF 生成一些 PDF 文件并将其保存在 PC 上。但它保存在我的网站文件夹所在的服务器上。
我需要将文件保存到 PC。当我在本地服务器(OpenServer)上工作时,它工作正常。 路径在 $_POST 中设置,因为我使用 AJAX 生成 pdf 如何解决?

代码:

require_once('tcpdf/tcpdf.php');


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


$pdf->SetCreator('God');
$pdf->SetAuthor('God');
$pdf->SetTitle('Contract');
$pdf->SetSubject('Contract');

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->setFontSubsetting(true);

$pdf->SetFont('dejavusans', '', 14, '', true);

$pdf->AddPage();

$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

 ob_start();
        include "page1.php";
        $content = ob_get_clean();
$html = $content;

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

 ob_start();
        include "page2.php";
        $content = ob_get_clean();
$html = $content;

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

 ob_start();
        include "page3.php";
        $content = ob_get_clean();
$html = $content;


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

$dirname = $_POST['dirname'];
$path = $_POST['path'] . $dirname . '\ ';
mkdir($path, 0700);

$filename = $_POST['filename'] . '.pdf';

$pdf->Output($path . $filename, 'F');

【问题讨论】:

    标签: php wordpress pdf web tcpdf


    【解决方案1】:

    在最后一行,使用选项“D”而不是“F”:

    $pdf->Output($path . $filename, 'F');
    

    如文档中所述,

    D:发送到浏览器并强制下载指定名称的文件 按名称。
    F:保存到本地文件,名称由name给出(可以 包括路径)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 2019-07-16
      • 2014-03-22
      • 2012-09-02
      相关资源
      最近更新 更多