Muhammad Ilyas
Muhammad Ilyas

Reputation: 45

How to set custom page size in fpdf php library?

I need some help with fPDF. I want to set up my custom page size (exactly: width 3 inch, and height 5 or 6 inch). it will create number of pages again height parameter .

i set the size array(3,5). it will create 5 page. I

found fPDF() manual (http://www.fpdf.org/) but there are only ready formats like A4, B5 etc. I have to set up my own page format.

<?php 
require_once('fpdf/fpdf.php');
//$fromat = array(3,5);
$pdf = new FPDF('p','in', [4.1,2.9]);
$pdf->SetTopMargin(50);
$pdf->Addpage();
$pdf->SetTitle("invoice");
$pdf->SetCreator("maqbool solutons");
$pdf->SetAuthor("my name");
$pdf->SetSubject("report");


$pdf->SetFont('Arial', 'B', '16');
$pdf->SetTextColor(155,14,9);// rgb
$pdf->SetDrawColor(155,14,9);
$pdf->SetfillColor(15,140,95);
$pdf->Cell(60,10, 'hello word');
$pdf->Cell(60,10,'powered by fpdf', 1, 0,'c',true);
$pdf->Cell(60,10,'powered by fpdf', 1, 2,'c');
$pdf->Cell(60,10,'powered by fpdf', 1, 1,'c');
$pdf->Image("images/coat.jpg", 10,20,10,35);
$pdf->MultiCell(94,10,"skldjfsldfsfjsdkfsjdlfjsdflkjsdflksjflksjdflskjfslkjfdslkfdjslkfdjslkfjslkfjslkfjsflkjsflkjsflksjflksjfslkjfslkjslkf",1,"L",false);
$pdf->Output("I", "invice.pdf");
 ?>[that is my file size][1]

when i add array of size

Upvotes: 1

Views: 10096

Answers (3)

Nicolas C.
Nicolas C.

Reputation: 598

As said in the documentation, when you call the constructor or AddPage, you can either give a String or an Array containing the width and height:

// AddPage([string orientation [, mixed size [, int rotation]]])
$pdf->AddPage("P", [3, 5]); // assuming you are using 'in' as unit

Or directly using the constructor:

// __construct([string orientation [, string unit [, mixed size]]])
$pdf = new FPDF('P','in',[3, 5]);

Upvotes: 1

Bernd Schuhmacher
Bernd Schuhmacher

Reputation: 139

I think you can set the page size with the constructor. I have not tested it but this should show you the way:

$format=array(3,5);
$pdf=new FPDF('P','in',$format);
$pdf->Open();
....

Upvotes: 0

Ruben Pauwels
Ruben Pauwels

Reputation: 380

You should should define it in your constructor like so:

$pdf = new FPDF('P','in',[3,6]);

You can find more info in tutorial #1 and in the manual > AddPage

Upvotes: 2

Related Questions