【问题标题】:Inserting Image in PDF using FPDF使用 FPDF 在 PDF 中插入图像
【发布时间】:2014-03-14 06:56:51
【问题描述】:

我想使用 PHP 创建 PDF,为此我使用 FPDF。现在我想在 PDF 顶部添加两个图像(一个在左角,一个在右角)。我为此使用以下代码,

代码:-

function Header () {
$this->Image('logo.png',10,20,33,0,'','http://www.fpdf.org/');    
$this->SetFont('Arial', 'B', 20);
$this->SetFillColor(36, 96, 84);
$this->SetTextColor(28,134,238);
$this->Cell(0, 10, "Your Car Comparison Document", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
$this->Cell(0, 10, "Thanks for visiting CarConnect.", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
}

但是当我添加图像代码时,它会在浏览器上显示 404 错误,否则它可以正常工作。

【问题讨论】:

    标签: php fpdf


    【解决方案1】:

    上周我也做了同样的事情。但是一个注释:

    404 错误 = 找不到页面;您的图像或路径可能是错误的。

    我使用了以下代码,图像大小为 20x10:

    $imagenurl = "../imgs/incgaminglabs.png"; // in my case
    
    // 1) left corner in coord x=1 and y=1
    $pdf->Cell(0, 0, $pdf->Image($imagenurl, 1,1,20,10), 0, 0, 'C', false,'');
    
    // 2) right corner in coord x=$pdf->GetX() - image width + 1 and y = $pdf->GetY() - image height + 1
    $pdf->Cell(0, 0, $pdf->Image($imagenurl, $pdf->GetX()-20+1,$pdf->GetY()-10+1,20,10), 0, 0, 'C', false,'');
    

    我希望它对你有用。尝试更改值。

    【讨论】:

      【解决方案2】:

      HTTP url 看起来不是正确的图像 url,请使用正确的图像 url 'http://www.fpdf.org/logo.png'Image 方法参数错误,请参阅打击

      //Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])
      
      
      $this->Image('http://www.fpdf.org/logo.png',10,20,33,0); 
      

      【讨论】:

        【解决方案3】:
        $pdf->Image('PATH/logo.png',10,3,50);
        

        【讨论】:

          【解决方案4】:

          确保您的 img 路径正确。您的脚本可能位于不同的文件夹中并被包含在内。在这种情况下,请确保您选择了正确的路径。

          【讨论】:

          • 在同一个文件夹中有一个图像(logo.png)我也放了一个完整的图像网址,但我面临同样的问题。
          猜你喜欢
          • 2022-12-13
          • 1970-01-01
          • 2011-04-09
          • 2015-12-31
          • 2013-09-05
          • 1970-01-01
          • 1970-01-01
          • 2021-11-03
          • 2016-10-21
          相关资源
          最近更新 更多