1- import './pdf.min.mjs'
2- import './pdf_viewer.mjs'
1+ import './lib/ pdf.min.mjs'
2+ import './lib/ pdf_viewer.mjs'
33import { addLink } from '../BootstrapBlazor/modules/utility.js' ;
4+ import Data from '../BootstrapBlazor/modules/data.js' ;
45
56if ( pdfjsLib != null ) {
67 pdfjsLib . GlobalWorkerOptions . workerSrc = './pdf.worker.min.mjs' ;
78}
89
9- export async function init ( id , invoke , scale , rotation , url , password = null ) {
10+ export async function init ( id , invoke , options ) {
1011 const el = document . getElementById ( id ) ;
1112 if ( el === null ) {
1213 return ;
1314 }
1415
15- await addLink ( './_content/BootstrapBlazor.PdfReader/pdf_viewer.css' ) ;
16-
17- scale = 1.5 ;
18- rotation = 0 ;
19- url = './samples/sample.pdf' ;
16+ await addLink ( './_content/BootstrapBlazor.PdfReader/css/pdf.css' ) ;
2017
2118 //const elementId = el.querySelector('canvas');
2219 //const pdf = new Pdf(elementId);
2320 //pdf.scale = scale;
2421 //pdf.rotation = rotation;
2522
26- // prepare loading options (optional password allowed)
27- const options = { url } ;
28- if ( password ) {
29- options . password = password ; // pre-supply if user already has it
30- }
31-
32- // begin loading document
3323 const loadingTask = pdfjsLib . getDocument ( options ) ;
3424
25+ loadingTask . onProgress = function ( progressData ) {
26+ console . log ( progressData . loaded , progressData . total ) ;
27+ } ;
28+
3529 // handle password only when required (optional password support)
3630 loadingTask . onPassword = function ( updatePassword , reason ) {
3731 if ( reason === pdfjsLib . PasswordResponses . NEED_PASSWORD ) {
@@ -44,7 +38,7 @@ export async function init(id, invoke, scale, rotation, url, password = null) {
4438 }
4539 } ;
4640
47- const container = document . getElementById ( "viewerContainer ") ;
41+ const container = el . querySelector ( ".bb-view-container ") ;
4842 const eventBus = new pdfjsViewer . EventBus ( ) ;
4943 const pdfViewer = new pdfjsViewer . PDFViewer ( {
5044 container,
@@ -55,39 +49,41 @@ export async function init(id, invoke, scale, rotation, url, password = null) {
5549 eventBus . on ( "pagesinit" , function ( ) {
5650 // We can use pdfViewer now, e.g. let's change default scale.
5751 pdfViewer . currentScaleValue = "page-width" ;
52+ console . log ( "pagesInit" ) ;
5853 } ) ;
5954
6055 // handle the promise
6156 const pdfDocument = await loadingTask . promise ;
6257 pdfViewer . setDocument ( pdfDocument ) ;
6358
64- // pdfDocument.then(function (doc) {
65- // pdf.pdfDoc = doc;
66- // pdf.pagesCount = doc.numPages;
67- // renderPage(pdf, pdf.pageNum);
68-
69- // // notify .NET side that document is loaded
70- // invoke.invokeMethodAsync('DocumentLoaded', {
71- // pagesCount: pdf.pagesCount,
72- // pageNumber: pdf.pageNum
73- // });
74- // })
75- // .catch(function (error) {
76- // console.error("PDF loading error:", error);
77-
78- // // handle password exceptions specifically
79- // if (error.name === "PasswordException") {
80- // console.error("Password required but not provided");
81- // }
82-
83- // // notify .NET side that document loading failed
84- // invoke.invokeMethodAsync('DocumentLoadError', error.message);
85- // });
86-
59+ // pdfDocument.then(function (doc) {
60+ // pdf.pdfDoc = doc;
61+ // pdf.pagesCount = doc.numPages;
62+ // renderPage(pdf, pdf.pageNum);
63+
64+ // // notify .NET side that document is loaded
65+ // invoke.invokeMethodAsync('DocumentLoaded', {
66+ // pagesCount: pdf.pagesCount,
67+ // pageNumber: pdf.pageNum
68+ // });
69+ // })
70+ // .catch(function (error) {
71+ // console.error("PDF loading error:", error);
72+
73+ // // handle password exceptions specifically
74+ // if (error.name === "PasswordException") {
75+ // console.error("Password required but not provided");
76+ // }
77+
78+ // // notify .NET side that document loading failed
79+ // invoke.invokeMethodAsync('DocumentLoadError', error.message);
80+ // });
81+
82+ Data . set ( id , pdfViewer ) ;
8783}
8884
8985export function dispose ( id ) {
90-
86+ data . remove ( id ) ;
9187}
9288
9389function getCanvas ( item ) {
@@ -135,6 +131,11 @@ class Pdf {
135131 }
136132}
137133
134+ export function navigateToPage ( id , pageNumber ) {
135+ const pdf = Data . get ( id ) ;
136+ pdf . currentPageNumber = pageNumber ;
137+ }
138+
138139export function firstPage ( invoke , elementId ) {
139140 const pdf = getPdf ( elementId ) ;
140141
0 commit comments