How to set filename of pdf when downloading

Hello,

at the moment the filename of a downloaded pdf-File is set to "undefined.pdf". We want to give this file a name.

I tried to set the filename in codebehind (PdfViewer.aspx.cs),  when I set the DocumentPath. Is this possible?
Alternatively i tried to set the filename in javascript after pressing the "download"-button.

Both attempts to set the filename werent successful.

Could you please show me in the attached project how to set the filename?
I would prefer the solution in code behind.

Thank you very much.
Matthias

Attachment: DownloadPDF_setFilename_9b135826.zip

5 Replies 1 reply marked as answer

AA Akshaya Arivoli Syncfusion Team January 26, 2021 12:02 PM UTC

Hi Matthias, 
  
We were currently checking on your query with the provided details, we will update you with more details on January 28, 2021 
  
Regards, 
Akshaya 



DO DotCom February 2, 2021 04:46 PM UTC

We encountered the same issue (but in Blazor), is there any update?


DM Dhivyabharathi Mohan Syncfusion Team February 3, 2021 01:39 PM UTC

Hi   DotCom , 
 
For ASP.NET Web Forms: 
 
In our EJ1 PDF Viewer, we can initially set the filename for the pdf document using fileName property. The document will be downloaded with the filename which we declared in the filename property. We have shared the sample and code snippet for your reference. 
 
Code snippet: 
 
 
var pdfviewerObj = $("#ContentPlaceHolder1_PdfViewer1").data("ejPdfViewer"); 
pdfviewerObj.fileName = "pdf-document.pdf"; 
 
 
 
Sample: 
 
For Blazor: 
 
If you want to use in blazor PDF Viewer, we can set the filename for downloaded document by using downloadFileName property. If we load the document as base 64 string, we must provide the document name using the property downloadFileName. And we have shared the code snippet and sample for your reference. 
 
Code snippet: 
 
 
<SfPdfViewerServer @ref="@PdfViewer" DocumentPath="@DocumentPath" DownloadFileName="@DownloadFileName"/> 
public string DownloadFileName { get; set; } = "Syncfusion.pdf"; /> 
 
 
 
 
Sample: 
 
 
 
Kindly try it and revert us, if you have any concerns about this. 
 
Regards, 
Dhivya. 


Marked as answer

MW Matthias Wagner April 7, 2021 02:49 PM UTC

Thanks for your response, but this wont work for me. I attached again my example.

  • I set the filename when initializing the pdfviewerObj
    var pdfviewerObj = $("#PdfViewer1").data("ejPdfViewer");
    pdfviewerObj.filename = "dummyName4711.pdf";
  • I also tried to set the filename when downloading the file or when i load the document
    <ej:PdfViewer id="PdfViewer1" runat="server" style="width: 100%" PdfService="Local" DownloadStart="docLoad" DocumentLoaded="docLoad"></ej:PdfViewer>
    function docLoad()
    {   var pdfviewerObjDownload = $("#PdfViewer1").data("ejPdfViewer");
         pdfviewerObjDownload.filename = "dummyName4713.pdf";
    }

But none of these ways works for me.
Can you give me a hint what is the problem?? 
Could be the reason, that I read the document as a bytearray and set the document path to it? (PdfViewer1.DocumentPath = data:application/pdf;base64,byteArray)

Regards 
Matthias


Attachment: Download_setFilename__Kopie_b37f234e.7z


DM Dhivyabharathi Mohan Syncfusion Team April 8, 2021 04:16 PM UTC

Hi Matthias, 
 
We have checked the sample which you have shared. In this, you have provided the filename for the document as “filename” instead of the property “fileName”. So, that the document is downloaded as undefined.pdf. We have modified the sample for your reference. 
 
 
Kindly try this and revert us, if you have any concerns about this. 
 
Regards, 
Dhivya. 


Loader.
Up arrow icon