库未使用Dotnet core和javascript加载PDFTron,库simpe_wasm存在问题

库未使用Dotnet core和javascript加载PDFTron,库simpe_wasm存在问题,javascript,.net,pdf,.net-core,pdftron,Javascript,.net,Pdf,.net Core,Pdftron,我正在处理项目(.Net Core)中一个模块的需求,该模块包含多个PDF操作,如从PDF转换为HTML,然后在web视图编辑器中编辑HTML,最后将其转换为PDF 我使用提供的JavaScript代码来使用基于web的PDF编辑器(PDFTRON)。我在提供的官方文档的帮助下尝试了手动集成。当我运行node js时,我能够成功地使用该库,但当我在Dotnet core中使用它时,它无法加载简单的_wasm/MemGrow.js.mem文件,该文件是MemGrow.js的子部分,请查看下面的屏幕

我正在处理项目(.Net Core)中一个模块的需求,该模块包含多个PDF操作,如从PDF转换为HTML,然后在web视图编辑器中编辑HTML,最后将其转换为PDF

我使用提供的JavaScript代码来使用基于web的PDF编辑器(PDFTRON)。我在提供的官方文档的帮助下尝试了手动集成。当我运行node js时,我能够成功地使用该库,但当我在Dotnet core中使用它时,它无法加载简单的_wasm/MemGrow.js.mem文件,该文件是MemGrow.js的子部分,请查看下面的屏幕截图以了解发生的错误

404错误

为web viewer配置的文件夹

代码如下:

Index.cshtml

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>
    Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.
    <label for="file_upload">Choose A file</label>
    <input type="file" id="file_upload" name="file_upload" accept=".pdf">
</p>
</div>
<div id='viewer' style='width: 1024px; height: 600px;'> </div>
<script src="~/WebViewer/lib/webviewer.min.js"> </script>
<script> 
const input = document.getElementById('file_upload');
  WebViewer({
    path: 'WebViewer/lib', // path to the PDFTron 'lib' folder on your server
    licenseKey: 'Insert commercial license key here after purchase',    
    initialDoc: 'files/sample.pdf',  // You can also use documents on your server
  }, document.getElementById('viewer'))
    .then(instance => {
        const docViewer = instance.docViewer;
        const annotManager = instance.annotManager;
        // const Annotations = instance.Annotations;
        input.addEventListener('change', () => {
            debugger;
            // Get the file from the input
            const file = input.files[0];
            instance.loadDocument(file, { filename: file.name });
        });

        docViewer.on('documentLoaded', () => {
            // call methods relating to the loaded document
        });
    });

欢迎

了解。
选择一个文件

const input=document.getElementById('file_upload'); 网络浏览器({ 路径:“WebViewer/lib”,//服务器上PDFTron“lib”文件夹的路径 licenseKey:“购买后在此插入商业许可证密钥”, initialDoc:'files/sample.pdf',//您还可以使用服务器上的文档 },document.getElementById('viewer')) 。然后(实例=>{ const docViewer=instance.docViewer; const annotManager=instance.annotManager; //const Annotations=instance.Annotations; input.addEventListener('change',()=>{ 调试器; //从输入中获取文件 const file=input.files[0]; loadDocument(文件,{filename:file.name}); }); docViewer.on('documentLoaded',()=>{ //调用与加载的文档相关的方法 }); });
在运行node js服务器时工作正常,屏幕截图如下,


正在寻求帮助以提供.net core中的解决方案。

我能够重现并解决此问题:

在项目的根目录中,
Startup.cs
需要修改以添加正确的MIME类型,如下所示

//需要添加Microsoft.AspNetCore.StaticFiles才能使用FileExtensionContentTypeProvider类型
// https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.staticfiles.fileextensioncontenttypeprovider?view=aspnetcore-3.1
使用Microsoft.AspNetCore.StaticFiles;
// ...
命名空间aspnetcoreapp
{
公营创业
{
// ...
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
var provider=new FileExtensionContentTypeProvider();
provider.Mappings[“.res”]=“应用程序/八位字节流”;
provider.Mappings[“.mem”]=“应用程序/八位字节流”;
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles(新的StaticFileOptions(){
ContentTypeProvider=提供程序
});
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapRazorPages();
});
}
}
}

我怀疑可能没有为IIS设置mime类型,这就是它返回404的原因。尝试为此处列出的扩展添加mime类型@mparizeau我在IIS中配置了文档链接中提供的所有mime类型,但问题仍然存在。接下来,我创建了新的web解决方案,并再次在wwwroot文件夹中配置了webviewer,但没有成功,我不知道我还遗漏了什么。我修改了您提供的代码,现在可以正常工作了。我感谢你的支持。干杯:)