A bit of experimenting.
Given a file temp.pdf in the current working directory . . .
xattr -w "com.apple.metadata:kMDItemAuthors" "diddles1234" temp.pdf
writes the string "diddles1234" to the Authors metadata field of temp.pdf.
xattr -w "com.apple.metadata:kMDItemTitle" "newmetatitle" temp.pdf
writes the string "newmetatitle" to Title metadata field of temp.pdf.
However, if you try to put spaces into the string like this:
xattr -w "com.apple.metadata:kMDItemTitle" "new meta title" temp.pdf
the title field will not be changed to "new meta title". In fact, if you start with "original title" as the value of kMDItemTitle, successfully change it to "newmetatitle", and then later try to change it again to "new meta title", the value of kMDItemTitle reverts to "original title". The OS appears to "forget" the intermediate change to "newmetatitle".
As best I can figure, in the event of a failed xattr write command, the original kMDItemTitle is rebuilt from semi-redundant data within the PDF--but more experimentation would be required to prove it. (The same is true of kMDItemAuthors, by the way.) Quick take away: The first two commands above will work if you don't use spaces in the strings to be inserted into the metadata fields. Someone more proficient in UNIX may have a better solution or explanation.