PDF.js是一個使用HTML5構建的可移植文檔格式庫。
PDF.js官網:http://mozilla.github.io/pdf.js/
下載下來的壓縮包包含兩個文件夾:build和web,打開web文件夾下的viewer.html,就能看到PDF的預覽效果了。
預覽的PDF文件是位於viewer.html同目錄下的compressed.tracemonkey-pldi-09.pdf,
而設置加載這個文件的地方是:與viewer.html同目錄下的viewer.js的DEFAULT_URL屬性,修改這個屬性的值就能夠預覽不同的文件,中英文的pdf文件都能成功預覽。
中文展示:修改viewer.html中的文件 <link rel="resource" type="application/l10n" href="locale/zh-CN/viewer.properties">
需要添加MIME,否則會報404
.net core 添加方式
修改 Configure 中的 UseStaticFiles
//添加MIME
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".properties"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
