5
votes

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.
1
header is only telling the browser what filename it 'should' use (and depending on the browser, it may ignore your definition), not what the actual physical file is named on the server. You would need to use the rename action to change the filename on the server after you are done.IncredibleHat
@IncredibleHat What rename does is only change the name of an existing file. What I want to do is give a random name say "Generated-Pdf.pdf" as title to my pdf which renders on screen.Deepak Singh

1 Answers

7
votes

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.