PdfReader.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="doc-viewer" ref="elementRef"></div>
  3. </template>
  4. <script>
  5. import '../../../public/pdf/image-viewer.umd';
  6. import '../../../public/pdf/style.css';
  7. import { defineComponent, onMounted, ref } from 'vue';
  8. export default defineComponent({
  9. components: {},
  10. props: ['fileUrl', 'fileName'],
  11. setup(props, { emit }) {
  12. const elementRef = ref(null);
  13. onMounted(() => {
  14. const options = {
  15. defaultUrl: props.fileUrl,
  16. resourcePath: 'pdf/',
  17. disableCORSOriginCheck: true,
  18. disableDocAnnotation: true,
  19. disableDraggingAndDropping: true,
  20. disablePopupList: false,
  21. showAnnotationMenu: false,
  22. textLayerMode: 1,
  23. appConfig: {
  24. toolbar: {
  25. toolbarViewerLeft: {
  26. pageNumber: false
  27. }
  28. }
  29. },
  30. toolbarControl: {
  31. download: false
  32. },
  33. locale: 'zh-cn'
  34. };
  35. const app = ImageViewer.createViewer(elementRef.value, options);
  36. app.readyPromise.then(() => {
  37. document.querySelector('#pdfFileName').innerHTML = props.fileName;
  38. });
  39. });
  40. return {
  41. elementRef
  42. };
  43. }
  44. });
  45. </script>
  46. <style>
  47. html[dir='ltr'] [data-id='toolbarViewerRight'] {
  48. display: none;
  49. }
  50. .pdf-document-viewer .toolbar {
  51. z-index: 999;
  52. }
  53. .pdf-document-viewer .annotation-control-bar__bottom {
  54. opacity: 0;
  55. display: none;
  56. }
  57. .pdf-document-viewer .annotation[data-subtype='Highlight'][data-custom-type='search'] .annotation-quad {
  58. fill: rgba(250, 200, 80, 0.3);
  59. }
  60. .pdf-document-viewer .annotation[data-subtype='Highlight'][data-custom-type='search'] .widget-content {
  61. fill: rgba(250, 200, 80, 0.3);
  62. }
  63. [data-id='toolbarContainer'],
  64. .findbar,
  65. .secondaryToolbar {
  66. height: 50px;
  67. padding-left: 50px;
  68. }
  69. .pdf-document-viewer input,
  70. .pdf-document-viewer button,
  71. .pdf-document-viewer select {
  72. border: none;
  73. cursor: pointer;
  74. }
  75. .pdfFileName {
  76. margin-top: 8px;
  77. flex: 1;
  78. }
  79. [data-id='toolbarViewerLeft'] {
  80. display: flex;
  81. }
  82. </style>
  83. <style scoped>
  84. .doc-viewer {
  85. height: 100%;
  86. }
  87. </style>