Editing an existing pdf file's metadata - php

I have some PDF files, on pdf version 1.6.
i have been trying the following libraries to edit the metadata of these pdf files:
Zend_Pdf class: which worked nicely for pdf version 1.5 or less. but had an error on parsing pdf of version 1.6
pdflib: not sure how i can edit an existing pdf file.
tcpdf: same problem that i couldn't find the functions for editing the existing pdf
someone also suggested just edit the pdf file by adding the following(for an example, title) to the end of the pdf file:
/Title (Title Text)
i would still wish to be able to do it using pdflib or some free source php libraries to achieve this.

PDFlib cannot edit an existing file, but you can copy the content of an existing file to a new file and read the metadata from the import document, change it and then write it to the new document.
http://www.pdflib.com/pdflib-cookbook/document-interchange/import-xmp-from-pdf/php-import-xmp-from-pdf/
is an example showing parts of this approach.

Related

pdftk is not generating pdf file

I tried using pdftk library from mikehaertl. I installed the composer file needed. But no pdf file is being generated. I also tried using the exact codes in mr.digital yt vid, still no file. Ive tried tweaking some codes like removing the access, uninstalling the lib and reinstalling it again.
You can check here the exact codes i tried using.
https://github.com/mrdigitalau/PHP-PDFTK-Tutorial
I removed the request methon from generate PHP file and define access with the generatePDF file from classes. Any help? Thankyou
Generate a downloadable PDF file and it should be automatically saved in the folder that is declared in the codes as well

Error converting .docx file (with .emf image background) to PDF

A Laravel-based application is converting documents (.doc, .docx, .pdf, .png, .otd, html, etc) to PDF so that they can all be merged together into a master PDF document. It is using a combination of plugins like PHPWord and DOMPDF Wrapper to do the file loading and creation. Every once and awhile, the process encounters an error due to a Word file.
ERROR: PhpOffice\PhpWord\Exception\InvalidImageException: Invalid
image: zip:// ... #word/media/image2.emf
The error is caused by an image background within the document that acts like a watermark. The PHPWord part that errors out is the PhpOffice\PhpWord\Element\Image->checkImage() method, but happens when the file is trying to be loaded.
Settings::setPdfRendererName(Settings::PDF_RENDERER_DOMPDF);
$pdfWord = IOFactory::load(storage_path() . '/app/uploads/randomfile.docx', 'Word2007');
How can the application convert a Word document, with an EMF image embedded, to a PDF?
For more code/info on how to recreate the error, a few issues exist in the Github PHPWord library.
Support EMF image #1480
Read docx error when contains image from remote url #1173
The environment-related information:
Server: Windows / IIS
PHP: 7.2.11
Laravel: 5.7.15
PHPWord: 0.15.0
EDIT:
I also tried to come at this from a different angle, to no avail. I tried using PHP's ZipArchive to unzip the docx file, remove the emf image from the document (ZipArchive::deleteName()), remove the reference to the emf image in the [Content_Types].xml (ZipArchive::getFromName()), then zip the docx file back up but that did not work. I can open the new docx file and see that the image is gone, but the PHPWord error still persists in the application.
It looks like PHPWord has a feature request open to solve this issue.
https://github.com/PHPOffice/PHPWord/issues/1480
I think you're on the right path with the file alteration, there is probably a reference to the image you are missing somewhere that PHPWord is still trying to access.
I would unzip the file on your local drive and grep (search the contents of the exploded file) the directory for the file you are looking for. This will show you where else you may need to remove it from being referenced in the file.

How can I add tags to a pdf document using PHP?

I wonder how I can add tags to a PDF document using PHP. The idea is that I can search for a document using the tag that I assigned it previously.
Your hint is exiftool to manipulate PDF tags. There is a PHP wrapper/driver for it. BIG NOTE that it is not recommended for production.
You have to install pdf to image converter on your server, here is the settings:
Please update the server with this package, so the conversion functionality works.
you can found the files i used on local server from
i used on windows using follwing instructions
Install gs909w32.exe (http://downloads.ghostscript.com/public/gs909w32.exe )
Install ImageMagick-6.8.9-4-Q16-x64-dll.exe (Link )
paste "php_imagick.dll" file in C:\wamp\bin\php\php5.4.3\ext\
include extensions= php_imagick.dll in php.ini file
It will convert your .pdf document to images (1 image/1 page), then you can tag....

create a .doc / pdf / odt using codeigniter and php

I followed this tut :
http://klewos.wordpress.com/2010/04/16/using-php-to-fill-a-word-document-quick-tip/
and all is fine till i open the downloaded .doc into libre office,
instead of outputing the doc content, it shows the full xml code as content !
Just note that i would prefer to create a PDF as final document but it seems easier with doc
I should miss a step with the xml to doc ?
if someone sees a better way to do this kind of thing (my base doc is 10 pages long so i don't really want to create a line by line pdf)
Anyhelp is welcome ;)
The article does mention that particular situation:
I’ve tried to open the Word 2003 XML document in OpenOffice.org 3.1.
Unfortunately, Writer wasn’t fooled by the .doc extension and opened
the document as plain text. Only after changing the document’s
extension to .xml, the editor opened it correctly. So, the documents
are portable after all.

Open epub files in PHP

I want to open an .epub document with PHP, to modify it (for example to add some text on the first page and last page) and to save it back to .epub I found some classes for saving a text into epub file, but I can't find anything about opening an epub in PHP.
epub files are just HTML+CSS files inside a ZIP archive (called the Open Container Format (OCF)) files with a different file extension :) So you can use PHP's ZipArchive class to work on the file.
There are libraries that support EPUB files. BookGlutton is one.

Categories