0

I'm trying to change the metadata of a document previously generated with another library (wkhtmltopdf) but when I create a mpdf objet change the data and save with the same name I'm just overwriting the previous pdf file for this empty new one. (with the proper metadata but empty)

$mpdf = new \Mpdf\Mpdf(['tempDir' => '/var/www/storage/temp']);
$mpdf->SetTitle('title');
$mpdf->SetAuthor('email');
$mpdf->SetKeywords('id');
$mpdf->Output('/var/www/storage/app/myfile.pdf');

With mpdf can I open previous document change the metadata and save the same document? (wkhtmltopdf can't handle metadata, just title)

arderoma
  • 388
  • 3
  • 15
  • There is a way to import pages from another document but when I call SetImportUse() php says that is a "undefined method" – arderoma Jul 01 '20 at 13:37
  • 1
    mPDF is a PDF generator, not an editor. It seems to have [limited support from importing](https://mpdf.github.io/what-else-can-i-do/importing-files-templates.html) but you aren't even trying to use it. – Álvaro González Jul 01 '20 at 13:53
  • I'm trying and it's working but it's messy (margins look weird because I'm importing one page inside of another). Any other idea how to edit the metadata of a pdf file with php? – arderoma Jul 01 '20 at 14:02

1 Answers1

0

mPDF is designed for creating new PDF files, not for changing/modifying/updating existing PDF files.

PHP solution:

  • Zend_Pdf as described here. (See also this answer.)

External Toolkits:

Note that some PDF metadata is duplicated and exists in both the regular PDF metadata and the XMP PDF metadata:

Since PDF v 1.6 metadata can be stored in the special XML document attached to the PDF (XMP - » Extensible Metadata Platform).

This XML document can be retrieved and attached to the PDF with Zend_Pdf::getMetadata() and Zend_Pdf::setMetadata($metadata) methods:

[...]

Common document properties are duplicated in the Info structure and Metadata document (if presented). It's user application responsibility now to keep them synchronized.

https://framework.zend.com/manual/1.12/en/zend.pdf.info.html

wq9578
  • 44
  • 5