从图像创建PDF时设置文档名称 [英] Set a Document Name when creating a PDF from an Image

查看:103
本文介绍了从图像创建PDF时设置文档名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从jpg图像创建pdf:

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');

现在,我最近看到Google索引了image.pdf文件,但由于它在Google搜索页上的标题为"Untitled"而不是"Image",因此名称为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.

在我看来,PDF似乎拥有自己的命名,而我的代码中却没有. 如何使用Imagemagick将无标题"更改为实际标题?

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?

推荐答案

这似乎与ImageMagick无关.您还有其他选择:

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.

对于它的价值,Zend PHP Framework可能是我的选择.尽管如果这不是您要做的事,那么exec()函数可能更有意义.

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.

这篇关于从图像创建PDF时设置文档名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆