PDF output with text #68
-
We've been using the example class QRImageWithText to add a text below the QR code. Because we will need to print the QR codes, we will probably need to switch from PNG to PDF so that it's in vectors. Is it possible to add a text in PDF just like we do it in PNG? If so, would it be possible to add some sample class? Thanks for your great work! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hey, i haven't done anything with the PDF output or FPDF itself yet and i'd recommend reading the FPDF docs in order to modify the PDF output (which is what i'd have to do by myself). If you set |
Beta Was this translation helpful? Give feedback.
-
Thanks for the super fast response :-) I'll try to explore what the options are. I guess the basic idea is to extend QRFpdf class and add the text in the process of file creation. Maybe outlining what should be in the dump function would be a great help because I'm getting a bit lost in all the dumping etc :-) |
Beta Was this translation helpful? Give feedback.
-
Extending the output modules is quite easy. Assuming you want to modify the FPDF object after writing the QR Code, just do as follows: namespace My\App;
use chillerlan\QRCode\Output\QRFpdf;
class QRFpdfCustom extends QRFpdf{
public function dump(string $file = null){
// force set returnResource to true to get the FPDF object in the next step
$this->options->returnResource = true;
// retrieve the FPDF object
$fpdf = parent::dump();
// modify the PDF
# $fpdf->Text($x, $y, 'text');
// ...
// proceed and mimic the output behaviour of the parent method
$pdfData = $fpdf->Output('S');
if($file !== null){
$this->saveToFile($pdfData, $file);
}
if($this->options->imageBase64){
$pdfData = sprintf('data:application/pdf;base64,%s', base64_encode($pdfData));
}
return $pdfData;
}
} However, if you need to modify the FPDF object on creation or while writing the QR Code, e.g. to modify size/position, you're better off copying the whole |
Beta Was this translation helpful? Give feedback.
-
Makes sense, thanks a lot for your help! |
Beta Was this translation helpful? Give feedback.
Extending the output modules is quite easy. Assuming you want to modify the FPDF object after writing the QR Code, just do as follows: