How to increase the paper size as per my image size using FPDF-php?

允我心安 提交于 2019-12-12 10:27:53

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/40650298/how-to-increase-the-paper-size-as-per-my-image-size-using-fpdf-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!