Pregunta

I'm creating dictionary in the catalog.

PDDocumentCatalog catalog = template.getDocumentCatalog();
COSDictionary dssDictionary=new COSDictionary();
dssDictionary.setItem(COSName.getPDFName("Certs"), cosCerts);;
catalogDictionary.setNeedToBeUpdate(true);      
catalogDictionary.setItem(COSName.getPDFName("DSS"), dssDictionary);

Ok. Everything works!

QUESTION 1) Now, Imagine that I need to update my dictionary.

I can get this dictionary like this:

COSBase dssCosBase = catalogDictionary.getDictionaryObject(COSName.getPDFName("DSS"));

Ok, It conataint my certificates. But how can I add another certificates here? It does any method for that.

QUESTION 2) I can get COSBase object but how can I get COSDictionary object?

¿Fue útil?

Solución

To make my comment an answer...

I answer the questions last to first:

Question 2) I can get COSBase object but how can I get COSDictionary object?

Simply check whether the COSBase you have got, also is an instance of COSDictionary using instanceof. If it is, cast to COSDictionary.

Question 1) But how can I add another certificates here?

After casting (see above) you can get the contained Certs dictionary, and after casting that again, you can work in that dictionary, e.g. adding another certificate.

In reaction to the comment, you found the following to work as you desired:

COSDictionary dssDictionary = (COSDictionary) catalogDictionary.getDictionaryObject(COSName.getPDFName("DSS"));

While this certainly will work for valid PAdES part 4 / PDF version 2 document security stores, you in general should be aware that there are broken documents for which DSS in the catalog is of a different type. Thus, I would always check with instanceof first.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top