PdfReader.vue 2.0 KB

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