PDF viewer override PDF generation server side

Posted by: grapecity on 24 May 2020, 5:28 am EST

  • Posted 24 May 2020, 5:28 am EST

    I have implemented Wijmo Report viewer and could make that server side renders the Flex report and set the recordset programatically by adding a custom ReportProvider:

       app.UseReportProviders().Add("memoryreports", new ReportDataProvider(GetFullRoot("ReportsRoot") + "\\MedicalReports\\TestReport.flxr", "TestReport"));
    

    Then on my ReportProvider class I override the following method to do my magic:

    
     protected override C1DocumentSource CreateDocument(string path, NameValueCollection args)
            {
                // in this sample, the path is "ReportsRoot/DataSourceInMemory.flxr/Simple List".
    
                var report = new C1FlexReport();
                report.Load(ReportPath, ReportName);
    
                UpdateDataSource(report, args); // HERE I SET RECORDSET MANUALLY
                return report;
            }
    

    Now, I want to do the same for the Wijmo PDF Viewer. I would like to intercept the call so I can generate my PDF on the fly based on the parameters sent from the UI.

    In the web example I see that the component sets the filePath to a static PDF:

    <wj-pdf-viewer serviceUrl="https://demos.componentone.com/ASPNET/c1webapi/4.5.20193.222/api/pdf"
                       filePath="PdfRoot/DefaultDocument.pdf"
                       :viewMode="viewMode" :mouseMode="mouseMode" :fullScreen="fullScreen" :zoomFactor="zoomFactor"
                       :viewModeChanged="viewModeChanged" :fullScreenChanged="fullScreenChanged" :zoomFactorChanged="zoomFactorChanged">
                   </wj-pdf-viewer>
    

    What I need is to intercept the call on the API before the PDF is sent back and then manually I can Load a Flex report and export it to PDF server side and then return the PDF path to the viewer.

    How can I do this?

  • Posted 26 May 2020, 12:35 am EST

    Hi,

    It seems that this is the same requirement as per your previous post here:

    https://www.grapecity.com/forums/wijmo/intercepts-pdf-export-on-w

    We are pasting the response here for reference:

    We are sorry but this is not possible because the PDF is generated on the client-side and is never sent back to the server. But we are investigating some other way to achieve this and we will update you if we will find any further information.

    Regards,

    Ashwin

  • Posted 26 May 2020, 1:50 am EST

    Hi thanks for your reply. This question is different from the other one because here is using Wijmo PDF Viewer. So for Wijmo PDF viewer the path is the PDF itself in the server, what I need here is a way to intercept that so instead of returning a static PDF we can generate it on the fly and after that just return the PDF path to the viewer.

    Thanks

  • Posted 26 May 2020, 11:37 pm EST

    Hi,

    Sorry for my misunderstanding and thank you for clarifying the issue further. I am investigating this and will update you as soon as possible.

    ~regards

  • Posted 27 May 2020, 5:18 pm EST

    Hi,

    I was not able to find a way by which we can update the PDF on the fly. But, I have asked the developers on whether this can be possible. The internal tracking id of the case is 438346. I will update you once I will hear from them.

    ~regards

  • Posted 29 May 2020, 2:02 pm EST

    Thanks, please let me know if developers know a way to do this. Thanks.

  • Posted 31 May 2020, 5:18 pm EST

    Hi Alejandro,

    The developers have said that this not possible. The PDF is taken directly from the filePath and it is sent back to the client after rendering. We cannot intercept this.

    ~regards

  • Posted 1 June 2020, 2:00 am EST - Updated 3 October 2022, 4:48 am EST

    So this means that the PDF Viewer is only for showing static PDFs files on server?

    I think PDF Viewer should also have the ability to call an API method that returns whatever PDF, so filePath is not always static.

    I was thinking on maybe before showing the PDF Viewer to execute a process on server to render the PDF and save it on server and then send the new generated PDF filePath parameter to the PDF Viewer so it can show it, but what about if the PDF is stored in the cloud, lets say AWS S3 bucket. Can we set the filePath to a external URL?

  • Posted 1 June 2020, 8:13 pm EST

    Hi,

    We are sorry but the PDF viewer only supports PDF from the C1WebApi. It cannot be used with AWS or any other links.

    But, you can use our Cloud Services to connect to AWS:

    https://www.grapecity.com/blogs/cloud-storages-crud-operations-restful-c1-webapi

    Currently, we are investigating whether we can connect cloud services with pdf services so that you can download the pdf from the aws server and then display it on the pdf viewer.

    ~regards

  • Posted 3 June 2020, 1:54 am EST

    Does Cloud Services has a separate cost from GrapeCity side? or is just the implementation?

    What I think would be better for the PDF Viewer is that you could set the filePath to your local PDF file and be able to intercept the call server side so you can create on the fly a PDF, pull it from cloud, etc, etc. That way it will be more flexible. Because what is a pain right now is that you must have to have the PDF file on server before you call the PDF Viewer and most of applications when you show a PDF is because you are going to generate it just right away.

    Thanks

  • Posted 4 June 2020, 8:12 pm EST

    Hi,

    Since you have purchased the Ultimate edition of ComponentOne, you can use the cloud services without any additional purchase.

    Regarding your main issue, I have asked the developers whether they can implement this feature in pdf services so that you can create/update the pdf dynamically. The internal tracking id of the case is 438346. I will update you once I will hear from them.

    ~regards

  • Posted 7 June 2020, 1:14 am EST

    Hi,

    The PDF can be shown in PdfViewer using the CustomStorage provider inherited from IStorageProvider. Using this Interface, we may implement the API which can show the files from local server and Cloud services with the help of C1Cloud Service WebApi.

    Find the attached demo sample<CustomPDFProviderWithCloudStorage.zip> for reference.

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 7 June 2020, 2:05 pm EST

    Thanks Manish, from the project you sent I can see two web applications, one is BlobPDFProvider and the second web application is C1.Api.CloudPDF. Both are not related correct? Because I can see that in C1.Api.CloudPDF project you have the same BlobStorageProvider class declared.

    Also in both projects I dont see where you register this provider. but in first project i dont see where you register this providers.

    In ReportViewer to register a provider I do:

            app.UseReportProviders().Add("memoryreports", new ReportDataProvider(GetFullRoot("ReportsRoot") + "\\MedicalReports\\TestReport.flxr", "TestReport"));
    

    But in PDFViewer do I have to register it? How does API knows that an specific provider has to be triggered?

    Thanks

  • Posted 7 June 2020, 6:06 pm EST

    Hi,

    Yes, both are projects are related. The C1.Api.CloudPdf is the WebApi project which will be used as serviceUrl for PdfViewer placed in the BlobPdfProvider projects “Home\Index.cshtml” file.

    For PDF service API, we need to register the providers the same as FlexReport in the Startup.cs file.

    In the startup file, the providers are registered as follows to work with both local and server implementation.

    #region ComponentOne StoragProviders
                app.UseStorageProviders().Add("Blob", new BlobStorageProvider("Files"));
                app.UseStorageProviders().Add("CloudPdf", new CloudStorageProvider(CloudType.AWS, "C1WebApi/Documents"));
                #endregion
    

    Please refer to the ReadMe.txt file for making sample working with cloud services.

    Hope it clears!

    Regards,

    Manish Gupta

  • Posted 8 June 2020, 2:22 am EST

    Ok I will take a look at readme file to make this work and try it.

    Thanks

Need extra support?

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

Learn More

Forum Channels