1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- "use strict";
- if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
-
- alert("Please build the pdfjs-dist library using\n `gulp dist-install`");
- }
- pdfjsLib.GlobalWorkerOptions.workerSrc =
- "../../node_modules/pdfjs-dist/build/pdf.worker.js";
- const CMAP_URL = "../../node_modules/pdfjs-dist/cmaps/";
- const CMAP_PACKED = true;
- const DEFAULT_URL = "../../web/compressed.tracemonkey-pldi-09.pdf";
- const PAGE_TO_VIEW = 1;
- const SCALE = 1.0;
- const ENABLE_XFA = true;
- const container = document.getElementById("pageContainer");
- const eventBus = new pdfjsViewer.EventBus();
- const loadingTask = pdfjsLib.getDocument({
- url: DEFAULT_URL,
- cMapUrl: CMAP_URL,
- cMapPacked: CMAP_PACKED,
- enableXfa: ENABLE_XFA,
- });
- (async function () {
- const pdfDocument = await loadingTask.promise;
-
- const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
- const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(pdfjsLib.version);
- if (match && (match[1] | 0) >= 3 && (match[2] | 0) >= 2) {
-
- const pdfPageView = new pdfjsViewer.PDFPageView({
- container,
- id: PAGE_TO_VIEW,
- scale: SCALE,
- defaultViewport: pdfPage.getViewport({ scale: SCALE }),
- eventBus,
- });
-
- pdfPageView.setPdfPage(pdfPage);
- return pdfPageView.draw();
- }
-
- const pdfPageView = new pdfjsViewer.PDFPageView({
- container,
- id: PAGE_TO_VIEW,
- scale: SCALE,
- defaultViewport: pdfPage.getViewport({ scale: SCALE }),
- eventBus,
-
- textLayerFactory: !pdfDocument.isPureXfa
- ? new pdfjsViewer.DefaultTextLayerFactory()
- : null,
- annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
- xfaLayerFactory: pdfDocument.isPureXfa
- ? new pdfjsViewer.DefaultXfaLayerFactory()
- : null,
- structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
- });
-
- pdfPageView.setPdfPage(pdfPage);
- return pdfPageView.draw();
- })();
|