requirejs 引用pdf.js的时候 保存 不使用require在控制台输出
define(['avalon','public','PDFJS'],function(avalon,public,PDFJS) {
public.showLoading();
var vm = avalon.define({
$id: 'fileCtrl',
tableObj:{
htxxzjbh :"", // 合同主键编号
fileurll :"", // 文件路径
htxxzjbh :"", // 合同主键编号
hetmchen :"", // 文件名称
},
initFunc: function() {
public.closeLoading();
var urls=decodeURI(location.hash);
var pIdx = urls.indexOf("param=");
if (pIdx > -1) {
var params = urls.substring(pIdx * 1 + 6);
if (params != "") {
vm.tableObj.htxxzjbh = params.split("&")[0];
vm.selectDetailEvt();
}
}
},
//查看详情
selectDetailEvt:function(){
var obj = {
htxxzjbh:vm.tableObj.htxxzjbh,
};
public.ajaxDataFetch({
type: 'post',
moke: true,
data:JSON.stringify(obj),
url: 'GET_APP_APPLY_CTCTINFO',
callback:function(data){
setTimeout(function(){
public.closeLoading();
},500);
if(data.code=='0000'){
var _href = window.location.host;
vm.tableObj.fileurll = data.data.fileurll;
vm.tableObj.htxxzjbh = data.data.htxxzjbh;
vm.tableObj.hetmchen = data.data.filename;
public.nodeReady({
elId: 'con',
callback: function(node){
PDFJS.getDocument(data.data.fileurll).then(pdf=>{
var numPages = pdf.numPages;
var start = 1;
renderPageAsync(pdf, numPages, start);
});
}
})
}else{
mui.alert(data.msg, ' ', function() {});
}
}
});
},
});
return vm;
});
function renderPage(pdf, numPages, current){
console.log("renderPage");
pdf.getPage(current++).then(page=>{
//console.log('page', page);
//page.getTextContent().then(v=>console.log(v));
var scale = 1.5;
var viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions.
var canvas = document.createElement("canvas");
var context = canvas.getContext('2d');
document.body.appendChild(canvas);
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context.
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
//next
if(current<=numPages)return renderPage(pdf, numPages, current);
});
}
async function renderPageAsync(pdf, numPages, current){
console.log("renderPage async");
for(let i=1; i<=numPages; i++){
// page
let page = await pdf.getPage(i);
let scale = 1.5;
let viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions.
let canvas = document.createElement("canvas");
let context = canvas.getContext('2d');
document.body.appendChild(canvas);
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context.
let renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
兄弟问题解决了吗, 我也遇到了,怎么依赖都找不到PDFJS这个对象