writing contents of a text file into a metadata tag

Started by jma1966, February 09, 2024, 10:51:09 AM

Previous topic - Next topic

jma1966

I am trying to determine (thus far unsuccessfully) the syntax so that I can import the contents of a text file ("text.txt") into the PDF "description" tag of a pdf document ("test_document.pdf"). 

perhaps something like this....?
   
exiftool -XMP-dc:Description<=@C:\file\path\to_\text.txt  path\to\test_doc\test_document.pdf
       
If this is possible, could this process then be done in a batch process permitting multiple unique pdf files to each have a unique text file write to them?
   
I'd appreciate any suggestions.  Thanks.
       
-John

StarGeek

You almost have it.  See the -TAG<=DATFILE option.  You also need to put quotes around that part so the command line doesn't interpret the less than sign < before exiftool can use it.

Quote from: jma1966 on February 09, 2024, 10:51:09 AMIf this is possible, could this process then be done in a batch process permitting multiple unique pdf files to each have a unique text file write to them?

As per the docs in that link, you can use %d, %f, and %e represent the directory, file name and extension of the original PDF so that you can create the name of the text file.  Assuming that the text file is in the same directory as the PDF and the same base name, your command would be something like

exiftool -ext pdf "-XMP-dc:Description<=%d%f.txt path\to\PDF_Dir\

This would process all the PDFs in "PDF_Dir", look for a matching .txt in the same directory and the same base name, and copy the entire contents into the Description tag.  See the -w (-TextOut) option for more details on the percent variables.

This command creates backup files.  Add -Overwrite_Original to suppress the creation of backup files.  Add -r to recurse into subdirectories.

Also take note that any changes exiftool makes to a PDF are reversible because exiftool uses the Incremental Update feature of PDFs to make changes.  The file needs to be re-linearized to make the changes permanent and remove any previous data.  See the PDF Tags page for details.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

jma1966

Thanks very much for you great advice.  It worked like a charm.   

Of course, I now have a new question...

1) I would like to apply this command
exiftool -ext pdf "-XMP-dc:Description"<=%d%f.txt path\to\PDF_Dir\
to additional subfolders and their contents (consisting of pdf files and corresponding text files).

Any thoughts about how that syntax would look?

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

jma1966

Thank you again!  Your help was spot on---and is very much appreciated.
--John