pdfjs版本替换
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
let DEFAULT_URL = ''
|
||||
let url = decodeURIComponent(window.location.search)
|
||||
let attIdIndex = url.indexOf('&fileId=')
|
||||
let typeIndex = url.indexOf('?sarType=')
|
||||
let numberIndex = url.indexOf('&pageNumber=')
|
||||
let attId = ''
|
||||
let sarType = 'INLAND_STAND'
|
||||
let pageNumber = 1
|
||||
let pageCount = 1
|
||||
let fileId = ''
|
||||
let queryAttUrl = '/api/lawss/sarStandFile/queryConvertAtt'
|
||||
if (attIdIndex > -1) {
|
||||
attId = url.substring(attIdIndex + 8, url.length)
|
||||
pageNumber = url.substring(numberIndex + 12, attIdIndex)
|
||||
sarType = url.substring(typeIndex + 9, numberIndex)
|
||||
if (sarType === 'INLAND_LAWS' || sarType === 'FOREIGN_LAWS') {
|
||||
queryAttUrl = '/api/lawss/sarLawsFile/queryConvertAtt'
|
||||
} else if (sarType === 'BUSS') {
|
||||
queryAttUrl = '/api/lawss/sarBussStandFile/queryConvertAtt'
|
||||
}
|
||||
$.ajax({
|
||||
url: queryAttUrl,
|
||||
async: false,
|
||||
type: 'GET',
|
||||
data: {
|
||||
attId: attId
|
||||
},
|
||||
success: function (res) {
|
||||
// res = JSON.parse(res)
|
||||
if (res.data != null) {
|
||||
pageCount = res.data.pageCount
|
||||
if (res.data.fileOldName !== null && res.data.fileOldName !== undefined) {
|
||||
document.title = res.data.fileOldName + '-在线查看'
|
||||
}
|
||||
// $('#pageCount').html(res.data.pageCount)
|
||||
fileId = res.data.id
|
||||
getFileInfo()
|
||||
} else {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// document.onkeydown = function () {
|
||||
// var e = window.event || arguments[0]
|
||||
// if (e.keyCode === 123) {
|
||||
// return false
|
||||
// } else if (e.ctrlKey || e.keyCode === 73) {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
// document.oncontextmenu = function () {
|
||||
// return false
|
||||
// }
|
||||
|
||||
function getFileInfo () {
|
||||
$.ajax({
|
||||
url: '/api/lawss/sarFileInfo/getPdfFileInfo',
|
||||
async: false,
|
||||
type: 'GET',
|
||||
data: {
|
||||
sarFileId: fileId,
|
||||
filePageNumber: pageNumber
|
||||
},
|
||||
success: function (res) {
|
||||
res = JSON.parse(res)
|
||||
if (res.data != null) {
|
||||
if (res.data.fileInfo != null) {
|
||||
let data = res.data.fileInfo
|
||||
let resultFileMsg = data.substring(30, data.length - 50)
|
||||
resultFileMsg = resultFileMsg.replace(/\*/g, 'A')
|
||||
let password = res.data.filePwd
|
||||
sessionStorage.setItem('fileInfoSteam', password)
|
||||
writeFile(resultFileMsg)
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
alert('文档未转换成功或本地读取不到该文档')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function writeFile (data) {
|
||||
var BASE64_MARKER = ';base64,' // 声明文件流编码格式
|
||||
var pdfAsDataUri = data
|
||||
var pdfAsArray = convertDataURIToBinary(pdfAsDataUri)
|
||||
DEFAULT_URL = pdfAsArray
|
||||
if (Number(pageCount) > 1) {
|
||||
if (Number(pageNumber) === 1 && Number(pageNumber) !== Number(pageCount)) {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').show()
|
||||
} else if (Number(pageNumber) !== 1 && Number(pageNumber) !== Number(pageCount)) {
|
||||
$('#upLoadingFile').show()
|
||||
$('#downLoadingFile').show()
|
||||
} else {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').hide()
|
||||
}
|
||||
} else {
|
||||
$('#upLoadingFile').hide()
|
||||
$('#downLoadingFile').hide()
|
||||
}
|
||||
}
|
||||
|
||||
function clickLoadFile (type) {
|
||||
if (type === 'up') {
|
||||
pageNumber = Number(pageNumber) - Number(1)
|
||||
} else {
|
||||
pageNumber = Number(pageNumber) + Number(1)
|
||||
}
|
||||
window.location.href = '/static/pdf/web/viewer.html?sarType=' + sarType + '&pageNumber=' + pageNumber + '&fileId=' + encodeURIComponent(attId)
|
||||
}
|
||||
|
||||
function convertDataURIToBinary (dataURI) {
|
||||
var raw = window.atob(dataURI) // 这个方法在ie内核下无法正常解析。
|
||||
var rawLength = raw.length
|
||||
// 转换成pdf.js能直接解析的Uint8Array类型
|
||||
var array = new Uint8Array(new ArrayBuffer(rawLength))
|
||||
for (let i = 0; i < rawLength; i++) {
|
||||
array[i] = raw.charCodeAt(i)
|
||||
}
|
||||
return array
|
||||
}
|
||||
Reference in New Issue
Block a user