Print in php custom paper

Asked

Viewed 112 times

0

How can I set up a paper size in php? for example: I have a 140mm x 160mm paper.

  • 2

    Are you sure you’re using the right tag? In principle, PHP does not have elaborate print functions. If possible, click edit and give more details, please. If you are talking about this: http://php.net/manual/pl/ref.printer.php, it is good to add in the question - if you are using some other technology, it is good to mention also.

  • @Bacco, there are alternatives as posted in my reply and use PHP, but I think it could include css and html tags...

1 answer

4

A tip, whenever I faced the problem I used some library to generate PDF files, FPDF is old but solves these problems. It will generate the PDF of the paper size you need. A minimum example

<?php
require('fpdf.php');
//aqui vc personiza o tamanho do papel
$pdf = new FPDF('P','mm',array(140,160));
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

Another option is Dompdf (converts html to pdf)

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
$customPaper = array(0,0,140,160); //personaliza aqui
$dompdf->set_paper($customPaper);

I prefer the FDPF for being faster

Browser other questions tagged

You are not signed in. Login or sign up in order to post.