You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Tilman Hausherr <TH...@t-online.de> on 2022/04/05 03:19:58 UTC

Re: How read Document Restriction Summary

Sounds like the MDP stuff... here some code from the examples subproject

     /**
      * Get the access permissions granted for this document in the 
DocMDP transform parameters
      * dictionary. Details are described in the table "Entries in the 
DocMDP transform parameters
      * dictionary" in the PDF specification.
      *
      * @param doc document.
      * @return the permission value. 0 means no DocMDP transform 
parameters dictionary exists. Other
      * return values are 1, 2 or 3. 2 is also returned if the DocMDP 
transform parameters dictionary
      * is found but did not contain a /P entry, or if the value is 
outside the valid range.
      */
     public static int getMDPPermission(PDDocument doc)
     {
         COSDictionary permsDict = doc.getDocumentCatalog().getCOSObject()
                 .getCOSDictionary(COSName.PERMS);
         if (permsDict != null)
         {
             COSDictionary signatureDict = 
permsDict.getCOSDictionary(COSName.DOCMDP);
             if (signatureDict != null)
             {
                 COSArray refArray = 
signatureDict.getCOSArray(COSName.REFERENCE);
                 if (refArray != null)
                 {
                     for (int i = 0; i < refArray.size(); ++i)
                     {
                         COSBase base = refArray.getObject(i);
                         if (base instanceof COSDictionary)
                         {
                             COSDictionary sigRefDict = (COSDictionary) 
base;
                             if 
(COSName.DOCMDP.equals(sigRefDict.getDictionaryObject(COSName.TRANSFORM_METHOD)))
                             {
                                 base = 
sigRefDict.getDictionaryObject(COSName.TRANSFORM_PARAMS);
                                 if (base instanceof COSDictionary)
                                 {
                                     COSDictionary transformDict = 
(COSDictionary) base;
                                     int accessPermissions = 
transformDict.getInt(COSName.P, 2);
                                     if (accessPermissions < 1 || 
accessPermissions > 3)
                                     {
                                         accessPermissions = 2;
                                     }
                                     return accessPermissions;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return 0;
     }

Tilman

Am 04.04.2022 um 15:50 schrieb Roberto Minoletti:
> Hello,
>
> how can we obtain the Document Restriction Summary from a PDF using PDFBox?
>
> We can actually manage without any issues the Permissions properties but not
> the Restrictions.
>
>   
>
> To be more specific the problem is that we have to sign a document in of a
> document management process but in case of the document is previously signed
> and blocked by the owner we need to detect it before to add a second
> signature to avoid to broke the previous signature.
>
> We have seen into the document restrictions that there is a parameter named
> "signature" that can be "allowed" or "not allowed" and we need to be able to
> read this value using PDFbox from pdf before to add the digital signature.
>
>   
>
> It seems that it is a common problem and I've found for example the same
> question here by other person:
>
> https://community.oracle.com/tech/developers/discussion/4495150/access-permi
> ssions-not-reflecting-on-pdf-document-restriction-summary-using-pdfbox
>
> but not able to find any answers.
>
>   
>
> Can someone help me to find the right function to get and parse
> restrictions?
>
>   
>
> Thank you in advance
>
> Roberto
>
>   
>
>   
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org