【问题标题】:How to increase the paper size as per my image size using FPDF-php?如何使用 FPDF-php 根据我的图像大小增加纸张大小​​?
【发布时间】:2016-11-17 08:50:04
【问题描述】:

当我尝试使用 PHP 和 FPDF 插入图像时,图像在 PDF 中未显示为原始图像。

我从这个link得到了fPDF

使用上面链接中的以下代码

require('lib/fpdf.php');
        $image = MEDIA_DIR."uploads/".$report_img.".png";
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->Image($image,10,10,200,500);
        $pdf->Output();

我无法按原样加载 1000px*10000px 大小的图像,它显示为压缩。

如何根据我的图像尺寸增加纸张尺寸?

【问题讨论】:

  • 您有问题吗?因为你有它的一个声明
  • 这里没有更新!!你的代码在哪里?
  • 现在添加代码。
  • 您是否在页眉上添加图像?还是在你的 fpdf 的体细胞中?
  • 在我的 PDF 正文中......

标签: php fpdf


【解决方案1】:

我通过将我的图像添加到如下单元格中得到它

require('lib/fpdf.php');
        $image = MEDIA_DIR."uploads/pdf_images/".$report_img.".png";
        list($width, $height, $type, $attr) = getimagesize($image);
        $pdf = new FPDF();
        $pdf->SetSize(($width/2)+110,($height*57/100)); //Custom function
        $pdf->AddPage('','custom');
        $pdf->cell(1000,1000,'',$pdf->Image($image,10,10,235,$height*18/100),'PNG');
        $pdf->Output();

将以下函数添加到 fpdf.php

function SetSize($width,$height)
{
    $this->StdPageSizes['custom']=array($width,$height);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2016-06-17
    • 1970-01-01
    相关资源
    最近更新 更多