Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 807
Deepak Singh Avatar asked Jul 04 '18 13:07

Deepak Singh


People also ask

How to set the PDF tab title in frame 2019?

In Frame 2019, you can set the PDF tab title using "File Info" in the book file. Open the book file and choose File > File Info. The File Info window opens. In the Title field, type the tab title. Choose Set to commit the change. Save the file. Now, when you generate the PDF, the new title should appear in the PDF tab title.

What happens if a PDF does not have a title?

If a PDF does not have a title, the filename appears in the results list instead. A file’s title is not necessarily the same as its filename. The Advanced area shows the PDF version, the page size, number of pages, whether the document is tagged, and if it’s enabled for Fast Web View.

How do I add custom properties to a PDF file?

Create document properties You can add custom document properties that store specific types of metadata, such as the version number or company name, in a PDF. Properties you create appear in the Document Properties dialog box. Properties you create must have unique names that do not appear in the other tabs in the Document Properties dialog box.

How do I add a description to a PDF file?

Add a description to Document Properties You can add keywords to the document properties of a PDF that other people might use in a search utility to locate the PDF. Choose File > Properties. Click the Description tab, and type the author’s name, subject, and keywords.


1 Answers

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.

like image 104
KenS Avatar answered Sep 27 '22 22:09

KenS