问题
I'm using the following code to create a pdf from a jpg image:
$im = new Imagick();
$im->readImage('./image.jpg');
$im->setImageFormat('pdf');
$im->writeImage('../images/pdf/image.pdf');
Now I recently Saw that google indexed the image.pdf file but as the title on the google search page it says "Untitled" instead of "Image" cause the name was image.pdf.
So to me it appears as if PDF had it's own naming which has been left out in my code. How can I change that "Untitled" to the actual title using Imagemagick?
回答1:
This doesn't appear possible to do with ImageMagick. You have a few other options:
- Purchase and use the PDFLib library: http://php.net/manual/en/book.pdf.php
- Use the Zend PHP framework; example of how to use it is here: Adding metadata to PDF via PHP with more information here: http://framework.zend.com/about/faq/
- Use the PHP exec() function to call an external program that can set the title
- OP mentioned in a comment there is FPDF as well: http://www.fpdf.org/ which appears it could be suitable as it has the ability to write a PDF file and set the title using its SetTitle(). FPDF hasn't been updated since 2011 and before that 2008. But, again, it appears that it would be suitable.
For what it is worth, the Zend PHP Framework would probably be my choice. Although if this isn't something you'll be doing a lot of, then the exec() function might make more sense.
来源:https://stackoverflow.com/questions/14921618/set-a-document-name-when-creating-a-pdf-from-an-image