简体   繁体   English

如何在blazor wasm中等待javascript保存pdf文件的文件名?

[英]How to wait for filename from javascript saving pdf file in blazor wasm?

I use this code from syncfusion: https://help.syncfusion.com/file-formats/pdf/create-pdf-document-in-blazor#steps-to-create-pdf-document-in-blazor-client-side-application there is function ExportToPdf.我使用来自 syncfusion 的代码: https ://help.syncfusion.com/file-formats/pdf/create-pdf-document-in-blazor#steps-to-create-pdf-document-in-blazor-client-side -应用程序有函数ExportToPdf。 How inside this ExportToPdf can code wait for user choosen filename and continue after saving file on disk?这个 ExportToPdf 如何在代码中等待用户选择的文件名并在将文件保存到磁盘后继续? I want to disable button to not allow it to press again until pdf file is completely saved.我想禁用按钮以不允许它再次按下,直到 pdf 文件完全保存。 And how to get filename user had choosen?以及如何获取用户选择的文件名?

Also there is this extension method: public static class FileUtil还有这个扩展方法:public static class FileUtil

{
    public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
       => js.InvokeAsync<object>(
           "saveAsFile",
           filename,
           Convert.ToBase64String(data));
}

Can someone explain to me how this lambda => expression works here?有人可以向我解释这个 lambda => 表达式在这里是如何工作的吗?

What that is doing is calling the saveAsFile function defined on the window object in the javascript file.这样做是调用在 javascript 文件中的 window 对象上定义的saveAsFile函数。 It passes two inputs to the function.它将两个输入传递给函数。 One is the filename and the other is the contents of the file in base64 encoded format.一个是文件名,另一个是 base64 编码格式的文件内容。 The javascript code in the browser then downloads those bytes to the specified filename.浏览器中的 javascript 代码然后将这些字节下载到指定的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM