Lock and digitally sign a pdf using Active Reports Server 12

Posted by: ricardo.pereira on 23 October 2019, 10:59 am EST

    • Post Options:
    • Link

    Posted 23 October 2019, 10:59 am EST

    Hi,

    Currently we are using your HTML5 Viewer implementation as per https://help.grapecity.com/activereports/webhelp/AR12/webframe.html#Viewing%20Reports%20using%20HTML5%20Viewer.html to render our RDLX reports via Active Reports Server v12, and we want to have the ability to lock and digitally sign a pdf.

    To achieve this we reached the conclusion that there are 2 options:

    1. We pass the report rendering results to our internal API and lock/sign it on there.

    2. We use our internal API to call the Active Reports API endpoint that generates the report (in essence generating the report twice), and then lock the pdf.

    What is your opinion on the above two solutions? Do you have any samples that perform either of the above solutions? I noticed that you have a sample using Winforms, however as we are using web technologies (dotnet core) this solution isn’t appropriate for us.

    Best Regards,

    Ricardo Pereira

  • Posted 24 October 2019, 2:19 am EST

    Hello Ricardo,

    You could refer to the Rest API HTML5 Sample(located at C:\ActiveReports 12 Server\SDK\Samples) for Web Sample.

    Also, I suggest you direct render the report in PDF Format using the following properties.

    https://help.grapecity.com/activereports/webhelp/AR12/webframe.html#GrapeCity.ActiveReports.Export.Pdf.v12~GrapeCity.ActiveReports.Export.Pdf.Page.Settings_members.html

    Also, refer the following link for PDF Export RestAPI:

    https://help.grapecity.com/activereports/webhelp/AR12ServerAPI/index.html#!/rendering_requests/post_api_reports_id_jobs_render

    Hope it helps.

    Thanks,

    Mohit

  • Posted 31 December 2019, 11:38 am EST

    Hi Mohit,

    Sorry for the late response but I’ve been pulled off to another piece of work and only now got back to this matter.

    Thank you for the links! They were helpful and I managed to export a pdf using the following endpoints:

    1st: POST /api/reports/{id}/jobs/render

    2nd: GET /api/reports/jobs/render/{request_id}

    When making the 1st call I’m using this model to feed the “settings” parameter:

                    ExtensionName = "pdf",
                    Timeout = 0,
                    UseCache = true,
                    ExtensionSettings = new ExtensionSettings(),
                    ReportParameters = new List<ReportParameter>
    

    My ExtensionSettings class looks like this:

            private class ExtensionSettings {
                public bool Encrypt { get; set; } = true;
                public string Permissions { get; set; } = "AllowPrint";
            }
    

    With “Encrypt=true” and "Permissions=“AllowPrint” I was able to lock the pdf by disallowing any actions available on Adobe PDF Reader beside the printing action.

    The problem I’m now having is that I also want to add a digital certificate “.pfx file” to my report when exporting it. While checking the documentation I found out two properties that seem to help me do what I intend to, so I added them to the ExtensionSettings class:

                public string SignatureCertificateFileName { get; set; } = "C:\\SomeCertificate.pfx";
                public string SignatureCertificatePassword { get; set; } = "SomePassword";
    

    If I then make the same calls, the 1st one will return a requestId (as expected) but the

    2nd one (GET /api/reports/jobs/render/{request_id}) returns an Internal Server Error.

    Can you help me understand what am I missing?

    Best regards,

    Ricardo Pereira

  • Posted 2 January 2020, 6:16 am EST

    After a bit of further investigation I found out that the error message I’m getting from the GET /api/reports/jobs/render/{request_id} call is:

    {"Type":"GrapeCity.ActiveReports.ReportException","StackTrace":null,"ErrorCode":"ReportError.0","Error":"The system cannot find the file specified.\r\n","ErrorParameters":[]}
    

    The .pfx file I’m trying to access is on my local machine and obviously exist.

  • Posted 2 January 2020, 6:25 am EST

    Managed to fix that error… I was incorrectly trying to access the file on my local machine, it needed to be available at the server.

    But now I get this error message:

    {"Type":"System.Runtime.Serialization.SerializationException","StackTrace":"   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)\r\n   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)\r\n   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)\r\n   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)\r\n   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)\r\n   at ActiveReports.Server.Runner.Remoting.CrossAppDomainExceptionWrapper.GetObjectData(SerializationInfo info, StreamingContext context)\r\n   at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)\r\n\r\n\r\n   at ActiveReports.Server.Runner.Executing.GenericExecutor`1.Execute()\r\n   at ActiveReports.Server.Runner.Runners.GenericTaskRunner`2.<>c__DisplayClasse.<DoWork>b__d(TExecutor executor)\r\n   at ActiveReports.Server.Runner.Executing.ExecutorFacade.UsingExecutor[TExecutor](IServiceProvider site, WorkDefinition workDefinition, LicenseStatus licenseStatus, Func`2 func, ExecutorSpecialization specialization)\r\n   at ActiveReports.Server.Runner.Runners.TaskRunner.UsingExecutor[TExecutor](ExecutorSpecialization specialization, Func`2 func)\r\n   at ActiveReports.Server.Runner.Runners.GenericTaskRunner`2.DoWork(CancellationTokenSource cancellationTokenSource)\r\n   at ActiveReports.Server.Runner.Runners.TaskRunner.<Run>b__8()\r\n   at System.Threading.Tasks.Task`1.InnerInvoke()\r\n   at System.Threading.Tasks.Task.Execute()","ErrorCode":"InternalServerError","Error":"Type '#Hkc.#Llc' in Assembly 'GrapeCity.ActiveReports.Export.Pdf.v12, Version=12.3.17127.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff' is not marked as serializable.","ErrorParameters":[]}
    
  • Posted 2 January 2020, 7:26 am EST

    Apparently it’s not possible to have a signatureCertificate and the Encrypt property set to true at the same time. After commenting the Encrypt and Permissions properties I was able to use the certificate.

    To achieve something similar to what I was aiming for I had to use the following ExtensionSettings:

            private class ExtensionSettings {
                public string SignatureCertificateFileName { get; set; } = @"C:\SomeCertificate.pfx";
                public string SignatureCertificatePassword { get; set; } = "SomePassword";
                public string SignatureCertificationLevel { get; set; } = "NoChangesAllowed";
            }
    
  • Posted 2 January 2020, 7:38 am EST

    Hello Ricardo,

    Sorry for the delay!

    I appreciate your analyzation on this issue. Yes, it is a limitation of PDF export. You can’t use the password encryption with the digital signature.

    I hope your problem is solved now.

    Happy New Year :slight_smile:

    Thanks,

    Mohit

  • Posted 6 January 2020, 1:34 pm EST

    Hello Mohit,

    Just wanted to let you know that the problem is solved :slight_smile: Thank you very much!!

    Happy New Year :slight_smile:

    Best regards,

    Ricardo Pereira

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels