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

本文是小编为大家收集整理的关于如何使用FPDF-php按照我的图像尺寸增加纸张大小?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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

我从这个链接

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

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

如何按照我的图像大小增加纸张尺寸?

推荐答案

我通过将图像添加到下面的单元格中来获得它.

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);
}

本文地址:https://www.itbaoku.cn/post/2090910.html

问题描述

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

I have got fPDF from this link

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();

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();

Add the below function to fpdf.php

function SetSize($width,$height)
{
    $this->StdPageSizes['custom']=array($width,$height);
}
相关标签/搜索