在web上加载pdf文件,并禁止用户下载和保存。起初考虑使用embed加载pdf,配置pdf连接尾部增长 #toolbar=0 ,但此方案仅在chrome下有效。所以考虑使用pdf.js作自定义pdf渲染。node
pdfjsLib.getDocument({
url: this.url,
withCredentials: true, // 容许携带cookie
});
复制代码
pdfjsLib.getDocument({
cMapUrl: 'https://unpkg.com/pdfjs-dist@2.0.943/cmaps/', // 使用cdn加载pdf.js提供的字体文件。
cMapPacked: true, // 此参数须要设为true
});
复制代码
pdfjsLib.GlobalWorkerOptions.workerSrc = 'static/js/bundle.js';
复制代码
// webpack配置
entry: {
main: 'xxxxx',
'pdf.worker': path.join(process.cwd(), 'node_moudules/pdfjs-dist/build/pdf.worker.entry')
},
output: {
filename: 'static/js/bundle.js',
publicPath: '/',
},
复制代码
document.oncontextmenu = () => {
event.returnValue = false;
// 兼容ie
return false;
};
复制代码