如何修复 linux 服务器中的 'TCPDF barcode not show'?

How to fix 'TCPDF barcode not show' in linux server?

我已经在本地服务器 (windows) 中使用了 tcpdf 条码并且出现了条码。在我将我的代码上传到 linux 服务器后,只有条形码没有出现。

我正在使用 codeigniter 和 composer tcpdf

本地截图: Screenshot local windows

截图linux服务器: screenshot linux server

这是我在里面的代码 application/library:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Pdf extends TCPDF{
  /**
  * PDF filename
  * @var String
  */
  public function __construct(){
    parent::__construct();
  }

  public function Header() {
    // Logo
    $image_file = base_url().'assets/images/logo/logo-wide.png';
    $this->Image($image_file, 10, 10, 50, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);
  }

  // Page footer
  public function Footer() {

    $image_file = base_url().'assets/images/email/footer_email.png'; 
    $this->Image($image_file, 0, 278, 210, 20, "PNG", "", "T", false, 300, "", false, false, 0, false, false, false);
    // Position at 15 mm from bottom 
    $this->SetY(0);
    // Set font 
    $this->SetFont("dejavusans", "", 9);
  }

  public function setupTicket($pdfName,$data){
    $this->SetCreator(PDF_CREATOR);
    $this->SetTitle($pdfName);
    $this->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdfName, PDF_HEADER_STRING);
    $this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    $this->SetDefaultMonospacedFont('helvetica');
    $this->SetHeaderMargin(PDF_MARGIN_HEADER);
    $this->SetFooterMargin(PDF_MARGIN_FOOTER);
    $this->SetMargins(PDF_MARGIN_LEFT, 35, PDF_MARGIN_RIGHT);
    $this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $this->SetFont('helvetica', '', 9);
    $this->setFontSubsetting(false);
    $this->AddPage(); 
    $style = array(
        'border' => 2,
        'vpadding' => 'auto',
        'hpadding' => 'auto',
        'fgcolor' => array(0,0,0),
        'bgcolor' => false, //array(255,255,255)
        'module_width' => 1, // width of a single module in points
        'module_height' => 1 // height of a single module in points
    );
    $params = $this->serializeTCPDFtagParameters(array($data['link_barcode'], 'QRCODE,H', 132, "", 25, 25, $style, 'N'));
    $htmlBarcode = '<tcpdf method="write2DBarcode" params="'.$params.'" />';

    $content = '
      <table cellpadding="4" >
       <tr>
        <td align="center" colspan="3" style="font-size:10px;border: 1px solid #e0e0e0;">
          <b>'.$data["ticket_name"].'</b>
          <br><br>'.$htmlBarcode.'
          <br>
          <b>'.$data["product_code"].'</b>
        </td>
       </tr>
      </table>';
    $this->writeHTML($content, true, false, true, false, '');
  }

  public function show_ticket($pdfName,$data){
    $this->setupTicket($pdfName,$data);
    $this->Output($pdfName.'.pdf', 'I');
  }
}

我忘记更改我的 tcpdf 配置。如果您使用作曲家,请打开文件夹 vendor/tecnickcom/tcpdf/config/tcpdf_config.php 。将define('K_TCPDF_CALLS_IN_HTML', false);改为true