coherentgraphics / cpdf-binaries

PDF Command Line Tools binaries for Linux, Mac, Windows
GNU Affero General Public License v3.0
604 stars 42 forks source link

Setting metadata #14

Closed adamdyson closed 7 years ago

adamdyson commented 7 years ago

I believe I've stumbled upon a bug while simply trying to update the metadata of an existing document.

I'm currently testing in a Windows environment using the command below:

cpdf.exe test.pdf -set-author "The Author" -set-creator "The Creator" -set-producer "The Producer" -set-title "The Title" -set-subject "The Subject" -set-keywords "The Key Words" -remove-annotations -o fixed.pdf

This is the file info outputted after running the command above:

Encryption: Not encrypted
Permissions:
Linearized: false
Version: 1.4
Pages: 1
Title: Test
Author:
Subject:
Keywords:
Creator: The Creator
Producer: The Producer
Created:
Modified:

When I remove the argument -remove-annotations this is the output:

Encryption: Not encrypted
Permissions:
Linearized: false
Version: 1.4
Pages: 1
Title: Test
Author:
Subject:
Keywords: The Key Words
Creator: The Creator
Producer: The Producer
Created:
Modified:

As you can see, the keywords get updated however the title, author and subject are not. When I update the metadata one attribute at a time, the file is updated correctly:

cpdf.exe fixed.pdf -set-title "The Title" -o fixed.pdf
cpdf.exe fixed.pdf -set-author "The Author" -o fixed.pdf
cpdf.exe fixed.pdf -set-subject "The Subject" -o fixed.pdf

I'm guessing this is a bug a not the expected behaviour? As it would be a waste of resources to have to perform multiple operations for something so simple.

adamdyson commented 7 years ago

After further testing I was able to update the metadata with the single command below.

cpdf.exe test.pdf -set-title "The Title" AND -set-author "The Author" AND -set-subject "The Subject" AND -set-keywords "The Key Words" AND -set-creator "The Creator" -set-producer "The Producer" -remove-annotations -o fixed.pdf

It's as if only the producer and creator metadata can be updated in a single action.

johnwhitington commented 7 years ago

Yes, this is the expected behaviour - AND is required to do several operations. However, producer and creator setting are "options" rather than "operations", because it is natural for them to change whenever a file is processed (some PDF processing programs will always change the producer to themselves when processing a file, for example).

The next release will contain an improved manual making clear the distinction between options and operations, since this is a common misunderstanding.

adamdyson commented 7 years ago

Ok thanks for clarifying.