PDF Utils, access privileges via .Net Client



  • Hi,

    I'm currently trying to control the 'access privileges' configuration for PDF Utils when generating a report from the C# client. I'd like to set an Owner Password and Printing Permission to High Resolution. The config in the studio would look like this:

    0_1699279608510_upload-c117661f-8469-43ed-b58d-4bef9a2c3a3b

    I see that on the C# Template class there is a PdfPassword property of type PdfPassword, however the PdfPassword class doesn't have the options for controlling the permissions described on the PDF Utils documentation. Instead it has a property called ProtectionLevel which is of type string.

    Setting the OwnerPassword property does result in the PDF being protected, however, I'm unsure of how to control the permissions through the ProtectionLevel property.

    My investigation thus far hasn't turned up much, the only mention of protection levels I managed to find was form the old jsreport-pdf-password extension, however, using those numbers didn't seem to have any effect.

    I see the PdfPassword class was last updated on Mar 7, 2020, and that the jsreport-pdf-password extension was deprecated in May 21, 2020, so I'm guessing that the PdfPassword class was created to work with the old extension not Pdf Utils.

    I ran out of time today, however, the next thing I was going to try was to use the overrides capability of the .Net Client to provide the pdfPassword config. The documentation says overrides are for providing config for unofficial extensions, but my guess is that it would work for official ones as well.

    Any advice would be greatly appreciated.

    Thanks :)



  • Hey,

    Just an update, I successfully got this working by using the overrides capability of the .Net Client.

    For anyone else trying to do the same thing, here is an example:

    var renderRequest = new RenderRequest
    {
      Template = ... // your template
      Data = ... // your data
      Overwrites = new 
      {
        Template = new
        {
          PdfPassword = new
          {
            OwnerPassword = "some password",
            Printing = "highResolution"
            // you can also add the other fields specified at 
            // https://jsreport.net/learn/pdf-utils#password-protection
          }
        }
      }
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.