Can you use the ExportPdf with Force proxy=true but preventing a redirect?

0 Answers 179 Views
PDF Export
Luc
Top achievements
Rank 1
Luc asked on 25 Aug 2023, 06:14 PM | edited on 25 Aug 2023, 07:02 PM

I am using the kendo-pdf-export and I need to send the resulting pdf to my backend API without opening or downloading the file locally. 

I used the following to achieve this:


 exportToPdf(pdfExport: { export: () => Promise<any>; }) {
    
    pdfExport.export().then((group) => {
      exportPDF(group).then((data) => {
        
        saveAs(data, 'Cdl-conformite-' + this.searchCriteria.courtier + '_' + this.datePipe.transform(this.searchCriteria.valueDate, 'yyyy-MM-dd') + '.pdf', {
          proxyURL: `${PATH}/savePdf`,
          forceProxy: true
        });
      });
    });
  }

I configured my backend to receive the file and can upload it to an S3 bucket. All this works fine.

My only problem is that when I click the button to save the pdf it redirects the UI to my /savePdf route which ... obviously is a blank page.

How can I force the control to use the proxy to send the file but not redirect the UI i.e. stay on the current page but submit the post asynchronously to my backend and do nothing else in the UI?

EDIT: I used proxyTarget = "_blank", it's better but the new window is focused and remains open which is not really acceptable.

Luc
Top achievements
Rank 1
commented on 25 Aug 2023, 07:50 PM

I found a way to close the window after the file is uploaded by returning html to the page from the API controller. 

Shouldn't be the API's job to control UI pages though. If there is a built-in solution, I'd love to use it instead. 

Yanmario
Telerik team
commented on 30 Aug 2023, 06:40 AM

Hi Luc,

Thank you for the provided details.

I do understand that in a perfect scenario, the UI should handle the upload without affecting the UI, but currently our PDFExport component doesn't provide such an option.  As a workaround, you already found setting the proxyTarget to _blank and I would suggest checking the following article:

Telerik-Kendo-UI : How to force exported PDF to open in a browser (howtosolutions.net)

The article is for jQuery, but they do share the same Drawing library.

Another theoretical option would be to create a custom proxy function that can be used to send requests to your backend API.

Also, there is the option to create a feature request in our feedback portal, where other users can vote and potentially bring it to our component as a new feature.

I hope this helps.

Regards,
Yanmario
Progress Telerik

Luc
Top achievements
Rank 1
commented on 30 Aug 2023, 11:55 AM

Thanks for your reply.

I could use none of your suggestions but have implemented a workable solution despite the feature not existing in the current lib.

No answers yet. Maybe you can help?

Tags
PDF Export
Asked by
Luc
Top achievements
Rank 1
Share this question
or