美文网首页
关于pdf 调用h5自带打印

关于pdf 调用h5自带打印

作者: 鄙人_阿K | 来源:发表于2020-12-27 16:14 被阅读0次

1、操作

1、带入js


image.png

2、代码


image.png
image.png

2、展示

image.png

3、pdfobject.min.js

/*
    PDFObject v2.0.201604172
    https://github.com/pipwerks/PDFObject
    Copyright (c) 2008-2016 Philip Hutchison
    MIT-style license: http://pipwerks.mit-license.org/
    UMD module pattern from https://github.com/umdjs/umd/blob/master/templates/returnExports.js
*/
(function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof module==="object"&&module.exports){module.exports=factory()}else{root.PDFObject=factory()}})(this,function(){"use strict";if(typeof window==="undefined"||typeof navigator==="undefined"){return false}var pdfobjectversion="2.0.201604172",supportsPDFs,createAXO,isIE,supportsPdfMimeType=typeof navigator.mimeTypes["application/pdf"]!=="undefined",supportsPdfActiveX,buildFragmentString,log,embedError,embed,getTargetElement,generatePDFJSiframe,isIOS=function(){return/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())}(),generateEmbedElement;createAXO=function(type){var ax;try{ax=new ActiveXObject(type)}catch(e){ax=null}return ax};isIE=function(){return!!(window.ActiveXObject||"ActiveXObject"in window)};supportsPdfActiveX=function(){return!!(createAXO("AcroPDF.PDF")||createAXO("PDF.PdfCtrl"))};supportsPDFs=supportsPdfMimeType||isIE()&&supportsPdfActiveX();buildFragmentString=function(pdfParams){var string="",prop;if(pdfParams){for(prop in pdfParams){if(pdfParams.hasOwnProperty(prop)){string+=encodeURIComponent(prop)+"="+encodeURIComponent(pdfParams[prop])+"&"}}if(string){string="#"+string;string=string.slice(0,string.length-1)}}return string};log=function(msg){if(typeof console!=="undefined"&&console.log){console.log("[PDFObject] "+msg)}};embedError=function(msg){log(msg);return false};getTargetElement=function(targetSelector){var targetNode=document.body;if(typeof targetSelector==="string"){targetNode=document.querySelector(targetSelector)}else if(typeof jQuery!=="undefined"&&targetSelector instanceof jQuery&&targetSelector.length){targetNode=targetSelector.get(0)}else if(typeof targetSelector.nodeType!=="undefined"&&targetSelector.nodeType===1){targetNode=targetSelector}return targetNode};generatePDFJSiframe=function(targetNode,url,pdfOpenFragment,PDFJS_URL,id){var fullURL=PDFJS_URL+"?file="+encodeURIComponent(url)+pdfOpenFragment;var scrollfix=isIOS?"-webkit-overflow-scrolling: touch; overflow-y: scroll; ":"overflow: hidden; ";var iframe="<div style='"+scrollfix+"position: absolute; top: 0; right: 0; bottom: 0; left: 0;'><iframe  "+id+" src='"+fullURL+"' style='border: none; width: 100%; height: 100%;' frameborder='0'></iframe></div>";targetNode.className+=" pdfobject-container";targetNode.style.position="relative";targetNode.style.overflow="auto";targetNode.innerHTML=iframe;return targetNode.getElementsByTagName("iframe")[0]};generateEmbedElement=function(targetNode,targetSelector,url,pdfOpenFragment,width,height,id){var style="";if(targetSelector&&targetSelector!==document.body){style="width: "+width+"; height: "+height+";"}else{style="position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%;"}targetNode.className+=" pdfobject-container";targetNode.innerHTML="<embed "+id+" class='pdfobject' src='"+url+pdfOpenFragment+"' type='application/pdf' style='overflow: auto; "+style+"'/>";return targetNode.getElementsByTagName("embed")[0]};embed=function(url,targetSelector,options){if(typeof url!=="string"){return embedError("URL is not valid")}targetSelector=typeof targetSelector!=="undefined"?targetSelector:false;options=typeof options!=="undefined"?options:{};var id=options.id&&typeof options.id==="string"?"id='"+options.id+"'":"",page=options.page?options.page:false,pdfOpenParams=options.pdfOpenParams?options.pdfOpenParams:{},fallbackLink=typeof options.fallbackLink!=="undefined"?options.fallbackLink:true,width=options.width?options.width:"100%",height=options.height?options.height:"100%",forcePDFJS=typeof options.forcePDFJS==="boolean"?options.forcePDFJS:false,PDFJS_URL=options.PDFJS_URL?options.PDFJS_URL:false,targetNode=getTargetElement(targetSelector),fallbackHTML="",pdfOpenFragment="",fallbackHTML_default="<p>This browser does not support inline PDFs. Please download the PDF to view it: <a href='[url]'>Download PDF</a></p>";if(!targetNode){return embedError("Target element cannot be determined")}if(page){pdfOpenParams.page=page}pdfOpenFragment=buildFragmentString(pdfOpenParams);if(forcePDFJS&&PDFJS_URL){return generatePDFJSiframe(targetNode,url,pdfOpenFragment,PDFJS_URL,id)}else if(supportsPDFs){return generateEmbedElement(targetNode,targetSelector,url,pdfOpenFragment,width,height,id)}else{if(PDFJS_URL){return generatePDFJSiframe(targetNode,url,pdfOpenFragment,PDFJS_URL,id)}else if(fallbackLink){fallbackHTML=typeof fallbackLink==="string"?fallbackLink:fallbackHTML_default;targetNode.innerHTML=fallbackHTML.replace(/\[url\]/g,url)}return embedError("This browser does not support embedded PDFs")}};return{embed:function(a,b,c){return embed(a,b,c)},pdfobjectversion:function(){return pdfobjectversion}(),supportsPDFs:function(){return supportsPDFs}()}});

相关文章

  • 关于pdf 调用h5自带打印

    1、操作 1、带入jsimage.png2、代码image.pngimage.png 2、展示 3、pdfobje...

  • iOS开发--Airprint

    Airprint是iOS系统自带的打印服务框架,利用她可以很简单系统打印服务,打印word,PDF,图片,也可以打...

  • 把网页下载为图片或打印成PDF

    最近遇到了需要把网页下载为图片和打印为PDF的需求,特此整理。 一、借助浏览器 一般浏览器都自带PDF打印功能: ...

  • web打开在线的pdf文件,禁用打印和下载功能

    网站上打开pdf文件,都是用浏览器查看pdf时自带的功能,可以下载打印,最近有一个需求,要求打开pdf后仅供用户预...

  • jq打印 调用浏览器自带打印

    项目中有时需要打印表格 或者文档php可以先生成pdf再打印,但是很耗资源,并且不好排版可以利用浏览器自带的打印功...

  • 关于rails打印pdf

    我这边使用的环境是 jruby-9.0.0 rails4.2 1.安装gem gem'prawn'gem'pra...

  • WebView和JS 交互

    注册JS调用的方法(H5调用WebView) 编写调用JS的方法(Webview调用H5并获得返回值) *H5需要...

  • 通过Dynamo批量打印PDF图纸

    最近有小伙伴留言,希望写一篇关于批量打印PDF图纸的教程,于是呢,这次就简单介绍一下批量打印pdf。 首先我在我的...

  • 2021-10-08-如何批量打印

    如何批量打印pdf word等,比如发票 wps批量打印功能 福昕pdf批量打印功能 先把pdf合并成一个文件,然...

  • 关于OC中遇到调用H5与其交互的

    OC 调用 JS 用苹果自带的返回键按钮处理如下(自定义的返回按钮) 如果是H5页面里面自带的返回按钮处理如下: ...

网友评论

      本文标题:关于pdf 调用h5自带打印

      本文链接:https://www.haomeiwen.com/subject/lrvonktx.html