I’ve a pdf file of a rule that need to pass a several approval. In the end of the file (content), I need to:
- Add a QR Code as an e-sign in the specific place, or
- Add a border-less table that include some text and a QR Code after the last content of the pdf. Which mean if the last content of pdf ends in the height(x) of 200, then the content should placed in (as an example) the height(x) of 210.
Is that possible?
TCPDF writeHtml
will place the generated html in the top of the page, while writeHTMLCell
and MultiCell
will need a specific x
and y
to be defined.
I’m also trying in MPDF, but it stuck like the TCPDF.
The code before writing the html looks like this,
$pageCount = PDF::setSourceFile($file);
$template = PDF::importPage($i);
$size = PDF::getTemplateSize($template);
PDF::AddPage($size['orientation'], array($size['width'], $size['height']));
PDF::useTemplate($template);
// After this, I need to call writeHtml, writeHTMLCell, or MultiCell, but none of those met what I need.
// Or placing an image with PDF::Image also need to define the x and y
...
// PDF::SetX()
// PDF::SetY()
// PDF::Image($qrPath, null, null, 12, 12, 'PNG');
// PDF::WriteHTML(view('document-requests.approver.stamp', ['qr' => $qrPath]), true, false, true, false, '');
PDF::Output($file, 'F');
#Edit
Another thing from mPDF
is that there’s an Overwrite
method, but it’s only overwrite the content created/generated by the library itself.
2
Answers
Answer:
It is possible to add a QR code to a specific location in a PDF using TCPDF or MPDF, but it will require some additional work, as none of the built-in functions directly meet your needs.
To add a QR code to a specific location in a PDF using TCPDF, you can use this code :
To add a QR code to a specific location in a PDF using MPDF, you can use Code :
Once you have positioned the table at the end of the PDF, you can output the PDF document.
I hope this helps to you.
Hi,
I use TCPDF in Laravel directly imported via composer. Using the package, you can call
$page_dimensions = $pdf->getPageDimensions($page_number)
With the package you are using, it would be (I think):
$page_dimensions = PDF::getPageDimensions($template);
Returns an array of page dimensions ref here TCPDF docs.
The dimensions you would need are from
$this->pagedim[$this->page]['MediaBox']
So something like:
$page_dimensions['MediaBox']['lly']
= lower-left y coordinate in points of the ‘meaningful page content’.I also use SetaSign Free PDF Document Importer (I use a few of their excellent products), which can extend TCPDF – their example shows importing a file via its MediaBox again its meaningful content.
Anyhow, I hope that helps.