如何使用FPDF-php根据我的图像尺寸增加纸张尺寸? [英] How to increase the paper size as per my image size using FPDF-php?

查看:123
本文介绍了如何使用FPDF-php根据我的图像尺寸增加纸张尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I tried inserting an image with PHP and FPDF, the image is not shown in PDF as the original.

我从此获得了fPDF.链接

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

Used the below code from the above link

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大小的图像,它显示为压缩状态.

I was not able to load 1000px*10000px size image as it is, it shows as compressed.

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

How to increase the paper size as per my image size?

推荐答案

我是通过将我的图片添加到如下所示的单元格中来实现的

I got it by adding my image into a cell like below

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

Add the below function to fpdf.php

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

这篇关于如何使用FPDF-php根据我的图像尺寸增加纸张尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆