3

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?

maddo7
  • 4,503
  • 6
  • 31
  • 51

1 Answers1

3

This doesn't appear possible to do with ImageMagick. You have a few other options:

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.

Community
  • 1
  • 1
TddOrBust
  • 450
  • 2
  • 9
  • It is worth a try. It doesn't look like fpdf has a straight image-> PDF conversion. It looks like you have to do new FPDF(), AddPage(), write the image as an image in the file using Image(), then write the file using Output(). My concern there would be that if the image is greater than the PDF page, then it wouldn't be resized or properly handled, but then I don't know what the other solutions would do. I've updated my answer to include FPDF as a possible option. FPDF does have a method though for writing the title: SetTitle() – TddOrBust Feb 17 '13 at 14:11
  • I suppose one thing you could do is write the image to the PDF using IMagick, then use FPDF to create a new PDF from that PDF and in doing so use SetTitle() from FPDF wot set the title. Not sure if that would be better than just using FPDF. – TddOrBust Feb 17 '13 at 14:17