ExifTool Forum

ExifTool => Newbies => Topic started by: jma1966 on February 09, 2024, 10:51:09 AM

Title: writing contents of a text file into a metadata tag
Post by: jma1966 on February 09, 2024, 10:51:09 AM
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
Title: Re: writing contents of a text file into a metadata tag
Post by: StarGeek on February 09, 2024, 11:32:35 AM
You almost have it.  See the -TAG<=DATFILE option (https://exiftool.org/exiftool_pod.html#TAG-DATFILE-or--TAG-FMT).  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 (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut) for more details on the percent variables.

This command creates backup files.  Add -Overwrite_Original (https://exiftool.org/exiftool_pod.html#overwrite_original) to suppress the creation of backup files.  Add -r (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.

Also take note that any changes exiftool makes to a PDF are reversible because exiftool uses the Incremental Update feature (https://www.debenu.com/kb/incremental-updates/) 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 (https://exiftool.org/TagNames/PDF.html) for details.
Title: Re: writing contents of a text file into a metadata tag
Post by: jma1966 on February 10, 2024, 03:36:17 PM
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?
Title: Re: writing contents of a text file into a metadata tag
Post by: StarGeek on February 10, 2024, 04:59:57 PM
Add the -r (-recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).
Title: Re: writing contents of a text file into a metadata tag
Post by: jma1966 on February 10, 2024, 08:20:43 PM
Thank you again!  Your help was spot on---and is very much appreciated.
--John