Where is metadata for PDF files? Can I insert metadata into any PDF file?
Solution 1
Ghostscript can insert or modify document metadata into any PDF.
Caveats: While doing so, Ghostscript will (1) first read in the complete PDF code, (2) second re-process that complete PDF code, (3) write out a completely new PDF file. This process can be wanted (could be for the advantage of the PDF quality, for example by additionally embedding previously missing fonts) or unwanted...
How to do it
Create a text file named mydocinfo.pdfmark and put the following content into it:
[ /Title (Jaziel's Important Document) /Author (Jaziel Aguirre) /Subject (Mr. Aguirre's experiments with pdfmark) /Creator (JA's Metadata Inserter) /ModDate (D:19700101000000+01'00') /Producer (A 'pdfmark' trick with Ghostscript) /Keywords (Metadata, Ghostscript, PDF, Linux) /CreationDate (D:20181229104653+01'00') /DOCINFO pdfmark
Note, that the opening
[
does NOT require a closing]
-- it is closed by the 'pdfmark' keyword.Now run this Ghostscript command to insert the new metadata into an existing PDF:
gs \ -o with-metadata.pdf \ -sDEVICE=pdfwrite \ existing.pdf \ mydocinfo.pdfmark
Check the new metadata:
pdfinfo with-metadata.pdf Title: Jaziel's Important Document Subject: Mr. Aguirre's experiments with pdfmark Keywords: Metadata, Ghostscript, PDF, Linux Author: Jaziel Aguirre Creator: JA's Metadata Inserter Producer: A 'pdfmark' trick with Ghostscript CreationDate: Sat Dec 29 10:46:53 2018 CET ModDate: Thu Jan 1 00:00:00 1970 CET Tagged: no UserProperties: no Suspects: no Form: none JavaScript: no Pages: 1 Encrypted: no Page size: 142.8 x 202.08 pts Page rot: 0 File size: 5394 bytes Optimized: no PDF version: 1.7
(Tested with Ghostscript v9.27.)
Solution 2
pdftk
is a command line utility allowing you to extract and modify the PDFs metadata using the dump_data
and the update_info
options.
The following command will extract the metadata of the input.pdf
to metadata
file:
pdftk input.pdf dump_data output metadata
Modify the content of the metadata
file using your text editor, then update the pdf file to a new output.pdf
:
pdftk input.pdf update_info metadata output output.pdf
To check the new pdf file (print to stdout):
pdftk output.pdf dump_data
Solution 3
Instead of writing the metadata into a text file first, you could of course also put it into one single command line:
gs -o with-meta.pdf -sDEVICE=pdfwrite -f existing.pdf -c "[ /Title (Jaziel's Important Document) /Author (Jaziel Aguirre) /Subject (Mr. Aguirre's experiments with pdfmark) /ModDate (D:19700101000000+01'00') /CreationDate (D:20181120102653+01'00') /Keywords (Metadata, Ghostscript, PDF, Linux) /Creator (JA's Metadata Inserter) /Producer (A 'pdfmark' trick with Ghostscript) /DOCINFO pdfmark"
or, with a formatting which is a bit more nice (readable):
gs -o with-meta.pdf \ -sDEVICE=pdfwrite \ -f existing.pdf \ -c "[ /Title (Jaziel's Important Document) /Author (Jaziel Aguirre) /Subject (Mr. Aguirre's experiments with pdfmark) /Keywords (Metadata, Ghostscript, PDF, Linux) /ModDate (D:19700101000000+01'00') /Keywords (Metadata, Ghostscript, PDF, Linux) /Creator (JA's Metadata Inserter) /Producer (A 'pdfmark' trick with Ghostscript) /CreationDate (D:20181120102653+01'00') /DOCINFO pdfmark"
Related videos on Youtube
![Jaaziel Aguirre](https://lh3.googleusercontent.com/-aK4sYCBmYIY/AAAAAAAAAAI/AAAAAAAAA_Q/qDRz9RkkXJM/photo.jpg?sz=256)
Jaaziel Aguirre
Updated on September 18, 2022Comments
-
Jaaziel Aguirre almost 2 years
I have many files of music; with the program mp3Tag, I had organized all of it. I have the correct metadata as it allows. I am looking for a free software that does the same, but for PDF files.
-
user755506 over 5 yearsHa!, I was thinking about adding pdftk's method a little bit later too. Now I can upvote your answer instead... :-)
-
Jaaziel Aguirre over 5 yearsHey, that's is simple. thanks for response. My ask was for Win10 but it helps me for the future, I had problems with Computers and just now I have a Pc with only win10. thanks
-
Jaaziel Aguirre over 5 yearswhat a useful, I will do this in some future. thanks
-
Jaaziel Aguirre over 5 yearsMmm Yes, but i am new here, so, I click the up arrow of corner?
-
user755506 over 5 years@JaazielAguirre: Exactly. Plus, you pick one (or none) of the answers to make it the "accepted" (best) answer for you...
-
holzkohlengrill almost 3 yearsDoes this also allow to remove metadata? If yes, how?
-
user755506 almost 3 years@holzkohlengrill: Yes, if you create the mydocinfo.pdfmark file with zero content inside the brackets, like this:
[ /Title () ....