vpdf.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <!--使用 pdfvuer 实现 滑动浏览 单印章-->
  3. <div class="pdf">
  4. <div class="loading" v-show="isloading">
  5. <span>pdf可能会加载时间有点长,请耐心等待...</span>
  6. </div>
  7. <!-- <div id="contentArea" class="show" v-if="!loading">
  8. <pdf :scale.sync="scale" :resize="true" ref="wrapper" class="p-pdf" :src="pdfData" v-for="i in numPages" :key="i"
  9. :id="i" :page="i" style="width: 100%">
  10. </pdf>
  11. </div> -->
  12. <iframe ref="viframe" style="width: 100%; height: 99%; border: none"
  13. :src="'https://cloud.cocorobo.cn/pdf.js/web/viewer.html?file=' + pdfUrl"></iframe>
  14. <!-- <div class="rightArea">
  15. <div class="toolGroup">
  16. <div class="page">第 {{ page }} / {{ numPages }} 页</div>
  17. <el-button type="primary" @click.stop="prePage">上一页</el-button>
  18. <el-button type="primary" @click.stop="nextPage">下一页</el-button>
  19. </div>
  20. </div> -->
  21. </div>
  22. </template>
  23. <script>
  24. // import pdfvuer from "pdfvuer"; // pdfvuer 版本为@1.6.1
  25. // import "pdfjs-dist/build/pdf.worker.entry";
  26. // const PDF = require("pdfjs-dist");
  27. // PDF.GlobalWorkerOptions.workerSrc = "../../common/pdf.worker.js";
  28. export default {
  29. name: "Pdfvuer",
  30. components: {
  31. // pdf: pdfvuer,
  32. },
  33. props: {
  34. // 当前pdf路径
  35. pdfUrl: {
  36. type: String,
  37. default:
  38. "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/0629%E5%AE%9E%E6%97%B6%E8%AF%BE%E5%A0%82%E6%A8%A1%E6%8B%9F%E6%BC%94%E7%A4%BA%E8%AF%BE%E4%BB%B61656920880446.pdf",
  39. },
  40. ppage: {
  41. type: Number,
  42. default: 1,
  43. },
  44. },
  45. data() {
  46. return {
  47. page: 1, // 当前页
  48. numPages: 0, // 总页数
  49. pdfData: undefined,
  50. inputPage: 1, // 输入的页码
  51. isloading: false,
  52. scale: "page-width",
  53. };
  54. },
  55. mounted() {
  56. // this.isloading = this.$loading.service({
  57. // background: "rgba(255, 255, 255, 0.7)",
  58. // target: document.querySelector(".loading"),
  59. // text: "加载中...",
  60. // spinner: "",
  61. // });
  62. this.isloading = false;
  63. this.$refs.viframe.onload = function () {
  64. this.isloading = false
  65. }
  66. console.log(this.isloading);
  67. // this.getPdf();
  68. },
  69. beforeDestroy() { },
  70. watch: {
  71. pdfUrl: function (s) {
  72. // this.isloading = this.$loading.service({
  73. // background: "rgba(255, 255, 255, 0.7)",
  74. // target: document.querySelector(".loading"),
  75. // text: "加载中...",
  76. // spinner: "",
  77. // });
  78. this.isloading = false;
  79. this.$refs.viframe.onload = function () {
  80. this.isloading = false
  81. }
  82. // this.getPdf();
  83. },
  84. },
  85. methods: {
  86. // 获取 pdf 信息
  87. getPdf() {
  88. this.pdfData = pdfvuer.createLoadingTask({
  89. url: this.pdfUrl,
  90. cMapUrl: "https://cdn.jsdelivr.net/npm/pdfjs-dist@2.16.105/cmaps/",
  91. cMapPacked: true,
  92. });
  93. this.pdfData
  94. .then((pdf) => {
  95. // this.isloading.close();
  96. this.isloading = false
  97. this.numPages = pdf.numPages;
  98. })
  99. .catch((err) => {
  100. console.log(err);
  101. });
  102. },
  103. // 上一页
  104. prePage() {
  105. let page = this.page;
  106. page = page > 1 ? page - 1 : 1;
  107. this.page = page;
  108. },
  109. // 下一页
  110. nextPage() {
  111. let page = this.page;
  112. page = page < this.numPages ? page + 1 : this.numPages;
  113. this.page = page;
  114. },
  115. },
  116. };
  117. </script>
  118. <style scoped>
  119. .loading {
  120. height: 100%;
  121. width: 100%;
  122. /* background: #000; */
  123. position: absolute;
  124. display: flex;
  125. align-items: center;
  126. justify-content: center;
  127. /* background-color: rgba(255, 255, 255, 0.7); */
  128. background-color: rgba(255, 255, 255, 1);
  129. z-index: 9;
  130. font-size: 20px;
  131. color: #007fff;
  132. }
  133. .pdf {
  134. height: 100%;
  135. width: 100%;
  136. position: relative;
  137. box-sizing: border-box;
  138. overflow-x: hidden;
  139. overflow-y: auto;
  140. }
  141. .pdf .show {
  142. margin: auto;
  143. width: 100%;
  144. display: flex;
  145. flex-wrap: wrap;
  146. }
  147. .pdf .show .p-pdf {
  148. overflow: hidden;
  149. }
  150. .pdf .show .p-pdf .line {
  151. position: absolute;
  152. width: 50px;
  153. right: -50px;
  154. background: rgb(255, 186, 96);
  155. height: 2px;
  156. }
  157. .pdf .show .p-pdf span {
  158. width: 100%;
  159. text-align: center;
  160. color: #fff;
  161. }
  162. .pdf .show .p-pdf span+span {
  163. margin-top: 10px;
  164. }
  165. .pdfbox {
  166. /* border: 3px solid #000; */
  167. /* box-sizing: border-box; */
  168. /* border-radius: 4px; */
  169. /* overflow: hidden; */
  170. }
  171. .pdf .pdf_footer {
  172. position: sticky;
  173. bottom: 0;
  174. left: 0;
  175. right: 0;
  176. padding: 10px 0;
  177. width: 100%;
  178. height: 75px;
  179. background-color: rgba(255, 255, 255, 0.5);
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. flex-direction: column;
  184. }
  185. .pdf .pdf_footer .info {
  186. display: flex;
  187. flex-wrap: wrap;
  188. width: 100%;
  189. justify-content: center;
  190. }
  191. .pdf .p-pdf .viewerContainer {
  192. width: 100%;
  193. }
  194. /* .pdf .pdf_footer .info div {
  195. width: 30%;
  196. } */
  197. .pdf .pdf_footer .operate {
  198. margin: 10px 0 0;
  199. display: flex;
  200. flex-wrap: wrap;
  201. justify-content: center;
  202. width: 100%;
  203. }
  204. .pdf .pdf_footer .operate div {
  205. text-align: center;
  206. font-size: 15px;
  207. }
  208. .pdf .pdf_footer .operate .btn {
  209. cursor: pointer;
  210. margin: 5px 10px;
  211. width: 100px;
  212. border-radius: 10px;
  213. padding: 5px;
  214. color: #fff;
  215. background-color: #066ebe;
  216. }
  217. .pdf::-webkit-scrollbar {
  218. /*滚动条整体样式*/
  219. width: 6px;
  220. /*高宽分别对应横竖滚动条的尺寸*/
  221. height: 6px;
  222. }
  223. /*定义滚动条轨道 内阴影+圆角*/
  224. .pdf::-webkit-scrollbar {
  225. border-radius: 10px;
  226. background-color: #b8bdc9;
  227. }
  228. /*定义滑块 内阴影+圆角*/
  229. .pdf::-webkit-scrollbar-thumb {
  230. border-radius: 10px;
  231. -webkit-box-shadow: inset 0 0 6px rgb(96, 125, 184);
  232. background-color: #2c5ab3;
  233. }
  234. </style>