Deepak Singh
Deepak Singh

Reputation: 650

Give the generated PDF a custom title

I've merged two PDF using the command

$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";
This is working for me. But the issue is title of the new generated PDF is not set as per I've set in the header('Content-Disposition: inline; filename="Test.pdf"'); I'm expecting the title to be Test.pdf but the title remains the title of the last PDF in the merged PDFs.

Upvotes: 6

Views: 2849

Answers (1)

KenS
KenS

Reputation: 31141

Sounds to me like you need to set the Title in the Document /Info dictionary of the PDF file. You can do that by sending a DOCINFO pdfmark.

You can pick up the pdfmark reference manual by googling for it. Its on the Adobe web site but they move the furniture so often there's no point in quoting today's URL.

You can find the DOCINFO pdfmark described on page 28 of the Acrobat 9 refrence (I've no idea if there's a newer one), you'll need something like:

[ /Title (My Title goes here) /DOCINFO pdfmark

That is PostScript so you need to supply it to Ghostscript as PostScript, which means you need the -c and -f switches. So something like:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName -c "[ /Title (My Title goes here) /DOCINFO pdfmark" -f

You're lucky I spotted this, since you didn't tag it with Ghostscript.

Upvotes: 11

Related Questions