123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- // 下载文件
- function dataURLtoBlob(dataurl) {
- var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
- bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n);
- }
- return new Blob([u8arr], { type: mime });
- }
- function downloadFile(blob, url, name){
- if (window.navigator.msSaveBlob) {
- try {
- window.navigator.msSaveBlob(blob, name)
- } catch (e) {
- console.log(e);
- }
- } else {
- // 谷歌浏览器 创建a标签 添加download属性下载
- var a = document.createElement("a");
- a.setAttribute("href",url);
- a.setAttribute("download",name);
- a.setAttribute("target","_blank");
- var clickEvent = document.createEvent("MouseEvents"); //创建
- clickEvent.initEvent("click", true, true);//初始化
- a.dispatchEvent(clickEvent);//触发
- }
- }
- function downloadFileByBase64(base64,name){
- var myBlob = dataURLtoBlob(base64);
- var myUrl = URL.createObjectURL(myBlob);
- downloadFile(myBlob, myUrl,name)
- }
- function downloadNewFile(){
- var base64 = NetcaPDFSeal.getSignPDFBytes();
- var file = 'data:application/pdf;base64,' + base64;
- var name = new Date();
- name = name.getTime();
- downloadFileByBase64(file, name+'.pdf');
- }
- // 演示功能
- function demonstrationFn(){
- var obj = {
- 'netcasave':false,
- 'netcaFirstSeparator':false,
- 'netcaSecondSeparator':false,
- 'netcaThirdSeparaor':false,
- 'netcaSetting':false,
- 'netcaAbout':false
- };
- checkObjHasOwnProperty(obj);
- hideExtraCheckboxesIE(obj);
- removeExtraCheckboxes();
- hideExtraCheckboxes();
- }
- /**检查obj是否有指定属性存在*/
- function checkObjHasOwnProperty(obj){
- if(!obj.hasOwnProperty('openFile')){
- obj.openFile = true
- }
- if(!obj.hasOwnProperty('netcasave')){
- obj.netcasave = true
- }
- if(!obj.hasOwnProperty('viewFind')){
- obj.viewFind = true
- }
- if(!obj.hasOwnProperty('zoomOut')){
- obj.zoomOut = true
- }
- if(!obj.hasOwnProperty('zoomIn')){
- obj.zoomIn = true
- }
- if(!obj.hasOwnProperty('scaleSelectContainer')){
- obj.scaleSelectContainer = true
- }
- if(!obj.hasOwnProperty('netcaFirstSeparator')){
- obj.netcaFirstSeparator = true
- }
- if(!obj.hasOwnProperty('previous')){
- obj.previous = true
- }
- if(!obj.hasOwnProperty('next')){
- obj.next = true
- }
- if(!obj.hasOwnProperty('netcaSecondSeparator')){
- obj.netcaSecondSeparator = true
- }
- if(!obj.hasOwnProperty('verify')){
- obj.verify = true
- }
- if(!obj.hasOwnProperty('netcasign')){
- obj.netcasign = true
- }
- if(!obj.hasOwnProperty('netcaThirdSeparaor')){
- obj.netcaThirdSeparaor = true
- }
- if(!obj.hasOwnProperty('netcaSetting')){
- obj.netcaSetting = true
- }
- if(!obj.hasOwnProperty('netcaAbout')){
- obj.netcaAbout = true
- }
- if(!obj.hasOwnProperty('netcastaff')){
- obj.netcastaff = true
- }
- if(!obj.hasOwnProperty('netcaorganization')){
- obj.netcaorganization = true
- }
- if(!obj.hasOwnProperty('netcalegalperson')){
- obj.netcalegalperson = true
- }
- if(!obj.hasOwnProperty('print')){
- obj.print = true
- }
- if(!obj.hasOwnProperty('closeFile')){
- obj.closeFile = true
- }
- }
- /**
- * 非IE浏览器下,移除多余的checkbox
- * */
- function removeExtraCheckboxes(){
- var arr = [2,7,11,14,15,16];
- if(!NetcaPDFSeal._isIE()){
- for(var i=0;i<arr.length;i++){
- (function(i){
- $('input[name="checkbox'+arr[i]+'"]').parent().remove()
- })(i);
- }
- }
- }
- /**
- * 根据toolbarButton的true/false,隐藏多余的checkbox
- * */
- function hideExtraCheckboxes(){
- var arr1 = [4,5,6,8,9,10,12,13,20,21,22,23,24,28];
- for(var j=0;j<arr1.length;j++){
- (function(j){
- if($('.netca_btn'+arr1[j]+'').css('display') === 'none'){
- $('input[name="checkbox'+arr1[j]+'"]').parent().remove()
- }
- })(j);
- }
- }
- /** IE 隐藏多余的checkbox
- * */
- function hideExtraCheckboxesIE(obj) {
- for (var k in obj) {
- if(k === 'print' && obj[k] === false){
- $('#checkbox20').parent().remove();
- }
- if(k === 'zoomOut' && obj[k] === false){
- $('#checkbox4').parent().remove();
- }
- if(k === 'zoomIn' && obj[k] === false){
- $('#checkbox5').parent().remove();
- }
- if(k === 'scaleSelectContainer' && obj[k] === false){
- $('#checkbox6').parent().remove();
- }
- if(k === 'previous' && obj[k] === false){
- $('#checkbox8').parent().remove();
- }
- if(k === 'next' && obj[k] === false){
- $('#checkbox9').parent().remove();
- }
- if(k === 'netcapage' && obj[k] === false){
- $('#checkbox10').parent().remove();
- }
- if(k === 'openFile' && obj[k] === false){
- $('#checkbox1').parent().remove();
- }
- if(k === 'netcasave' && obj[k] === false){
- $('#checkbox2').parent().remove();
- }
- if(k === 'viewFind' && obj[k] === false){
- $('#checkbox3').parent().remove();
- }
- if(k === 'netcaFirstSeparator' && obj[k] === false){
- $('#checkbox7').parent().remove();
- }
- if(k === 'netcaSecondSeparator' && obj[k] === false){
- $('#checkbox11').parent().remove();
- }
- if(k === 'netcaThirdSeparaor' && obj[k] === false){
- $('#checkbox14').parent().remove();
- }
- if(k === 'verfity' && obj[k] === false){
- $('#checkbox13').parent().remove();
- }
- if(k === 'netcaSetting' && obj[k] === false){
- $('#checkbox15').parent().remove();
- }
- if(k === 'netcaAbout' && obj[k] === false){
- $('#checkbox16').parent().remove();
- }
- if(k === 'netcasign' && obj[k] === false){
- $('#checkbox21').parent().remove();
- }
- if(k === 'netcastaff' && obj[k] === false){
- $('#checkbox22').parent().remove();
- }
- if(k === 'netcaorganization' && obj[k] === false){
- $('#checkbox23').parent().remove();
- }
- if(k === 'netcalegalperson' && obj[k] === false){
- $('#checkbox24').parent().remove();
- }
- if(k === 'closeFile' && obj[k] === false){
- $('#checkbox28').parent().remove();
- }
- }
- }
- function getSignCallBack(res){
- console.log("签名信息", JSON.parse(res))
- }
- function getVerifyCallBack(res){
- console.log("验证信息", JSON.parse(res))
- }
- // NetcaPDFSeal.setSignCallbackEvent(getSignCallBack);
- // NetcaPDFSeal.setVerifyCallbackEvent(getVerifyCallBack);
|