Q: I want digitally sign PDF documents by creating form field of
e_signature type. Signature field value must be a signature dictionary
(PDF reference 1.7, chapter 8.7, table 8.102) that must contain
Contents entry of "byte string" type described in PDF reference,
chapter 3.2.2 Hexadecimal strings: "A hexadecimal string is written as
a sequence of hexadecimal digits enclosed in angle brackets, e.g. /
Contents <0e34f5...4eff>". Unfortunately i have not found a function
suporting this format. Both Obj::PutString and Obj::PutText outputting
the /Contents (0e34f5...4eff). Is there any way to write a hexadecimal
string entry to PDF dictionary?
A: In PDF a byte string can be encoded using hex (where the string
data is surrounded with '<>' brackets) or octal+ PDFDocEncoding (where
the string data is surrounded with '()' brackets).
To a PDF consumer there is no difference between these two
representations and as a result you don't need to explicitly hex
encode the string. Add '/Contents' is the signature dictionary simply
call mydict.PutString("Contents", buffer, buffer_size).
Now, if you prefer hex strings you can pass
'pdftron.SDF.SDFDoc.SaveOptions.e_hex_strings' flag in the call to
doc.Save() method and all string in the resulting PDF will be hex