1

I am converting many .pdf graphics into .png and I want to keep the metadata of the .pdf files, e.g., Author, Creator, Title, and so on, in the .png.

Is there any way to transfer the metadata from a .pdf into a .png? Or more generally from a file into another file?

loved.by.Jesus
  • 2,266
  • 28
  • 34

2 Answers2

0

I can offer a version with Unix commands for the particular case PDF->PNG (it may work for other target pictures formats). Maybe similar commands are available in Windows.

The method consists of two steps that are piped:

  1. Get the metadata of a .pdf file

    pdfinfo myfile.pdf
    
  2. Get this metadata into the .png file. (See this post for more information)

    mogrify -comment "my metadata" myfile.png 
    

I found that .png files do not have such an easy metadata managing as .pdf, therefore, I just used mogrify a command of ImageMagick that inserts data as a "comment" in the image. This comment can be retrieved by running identify.exe -verbose plogo.png | grep -i "comment:" or just identify.exe -verbose plogo.png

Now as pipe in Unix works like that:

  pdfinfo myfile.pdf | tr '\n' ' ' | xargs -I metadata mogrify -comment "metadata" myfile.png

Note: the tr '\n' ' ' pipe transforms the line breaks in spaces, so that the whole metadata of the pdf can be inputed as a one-line string into the .png

If you want to select only certain entries of the metadata, you can use grep command to filter. For example, here we extract title, author, and creator of the whole .pdf metadata.

  pdfinfo myfile.pdf | grep -i 'title\|author\|creator' | tr '\n' ' ' | xargs -I metadata mogrify -comment "metadata" myfile.png
loved.by.Jesus
  • 2,266
  • 28
  • 34
0

This is the most practical and powerful possibility exiftool, an application for Linux, MacOS, and Windows.

You can transfer all metadata tags from one file into another preserving name and for any file format.

exiftool -tagsfromfile <source-file> <target-file>

For example, here I transfer the metadata from a .pdf to a .png

exiftool -tagsfromfile mysource.pdf mytarget.png

Filtering tags: You can also choose the tags to be transferred. For example, if I only want to transfer title, author, and creator, I set the option -<tag>

exiftool -tagsfromfile mysource.pdf -title -author -creator mytarget.png
loved.by.Jesus
  • 2,266
  • 28
  • 34