|
| 1 | +--- |
| 2 | +title: Changing the default file name and download the file after setting its content through the fromFile method |
| 3 | +description: Learn how to update the default file name and download the pdf file after setting its content in RadPdfViewer through the fromFile method |
| 4 | +type: troubleshooting |
| 5 | +page_title: Changing the default file name and download the file after setting its content through the fromFile method |
| 6 | +slug: pdfviewer-rename-download-file-name |
| 7 | +position: |
| 8 | +tags: |
| 9 | +ticketid: 1575749 |
| 10 | +res_type: kb |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>RadPdfViewer for ASP.NET AJAX</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | + |
| 24 | +## Description |
| 25 | +Learn below how to update the default file name and download the pdf file after setting its content in RadPdfViewer through the fromFile method. |
| 26 | + |
| 27 | +## Solution |
| 28 | +Here is an example that shows how to change the default file name and download the file after setting its content through the fromFile method: |
| 29 | + |
| 30 | + |
| 31 | +````ASPX |
| 32 | + <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.js"></script> |
| 33 | + <script type="text/javascript"> |
| 34 | + window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.2/pdf.worker.js'; |
| 35 | + </script> |
| 36 | + <div id="main"> |
| 37 | + <input type="text" placeholder="Type your name" value="John" /> |
| 38 | + <input type="text" placeholder="Type your comment" value="Smith" /> |
| 39 | + <telerik:RadPushButton OnClientClicked="exportPDF" runat="server" Text="Export page to PDF" ID="Export1" AutoPostBack="false"></telerik:RadPushButton> |
| 40 | + </div> |
| 41 | + <telerik:RadClientExportManager runat="server" ID="RadClientExportManager1" OnClientPdfExporting="OnClientPdfExporting"> |
| 42 | + </telerik:RadClientExportManager> |
| 43 | + <telerik:RadPdfViewer runat="server" ID="RadPdfViewer1" Height="550px" Width="100%" Scale="0.9"> |
| 44 | + |
| 45 | + </telerik:RadPdfViewer> |
| 46 | + <script> |
| 47 | + var $ = $telerik.$; |
| 48 | + function exportPDF() { |
| 49 | + $find('<%=RadClientExportManager1.ClientID%>').exportPDF($("#main")); |
| 50 | + } |
| 51 | + function OnClientPdfExporting(sender, args) { |
| 52 | + var data = args.get_dataURI().split(',')[1]; |
| 53 | + setData(data); |
| 54 | + args.set_cancel(true); |
| 55 | + } |
| 56 | + function setData(data) { |
| 57 | + var RadPdfViewerObject = $find("<%=RadPdfViewer1.ClientID %>"); |
| 58 | + RadPdfViewerObject.get_kendoWidget().options.messages.defaultFileName = "Put here the desired download file name"; |
| 59 | + RadPdfViewerObject.fromFile({ data: data }); |
| 60 | + setTimeout(function () { |
| 61 | + RadPdfViewerObject.get_kendoWidget().execute({ command: "DownloadCommand" }); |
| 62 | + }, 1000); |
| 63 | + return false; |
| 64 | + } |
| 65 | + </script> |
| 66 | +```` |
| 67 | + |
| 68 | +Here is another example with a slightly different approach: https://dojo.telerik.com/oVIxUsIr/3. |
| 69 | + |
| 70 | + |
0 commit comments