Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose an example for the single page viewer #8951

Closed
timvandermeij opened this issue Sep 24, 2017 · 8 comments
Closed

Compose an example for the single page viewer #8951

timvandermeij opened this issue Sep 24, 2017 · 8 comments

Comments

@timvandermeij
Copy link
Contributor

timvandermeij commented Sep 24, 2017

In pull request #8724 a single page viewer has been implemented. It would be nice to have a components example in the examples folder that demonstrates how to use this viewer.

@pixelexel
Copy link
Contributor

Hi! I'd like to address this issue. This is my first time solving an issue on Github so I'd love it if you could help me to figure out how to get started.
I've already got a local copy running with the gulp server.

@timvandermeij
Copy link
Contributor Author

There are component examples in the https://github.com/mozilla/pdf.js/tree/master/examples/components folder. The objective of this patch is to add an example that uses PDFSinglePageViewer. Like the other examples there, it can just load the default Tracemonkey PDF file.

@pixelexel
Copy link
Contributor

Thanks! I'll try to work on this.

@pixelexel
Copy link
Contributor

So, I'm getting a little confused here. This is what I understood:
In the components folder, pageviewer.js is an example that uses pdf_page_view.js to display pdf files normally. I need to create an example like singlepageviewer.js that uses pdf_single_page_viewer.js.

Am I along the right path so far?

So basically is this what I need to edit from the pageviewer.js file so that it makes use of the single page viewer?

return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
    // Creating the page view with default parameters.
    var pdfPageView = new PDFJS.PDFPageView({
      container: container,
      id: PAGE_TO_VIEW,
      scale: SCALE,
      defaultViewport: pdfPage.getViewport(SCALE),
      // We can enable text/annotations layers, if needed
      textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
      annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
    });
    // Associates the actual page with the view, and drawing it
    pdfPageView.setPdfPage(pdfPage);
    return pdfPageView.draw();
  });

Here is what singlepageviewer.js contains as the edited portion:

return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
    // Creating the page view with default parameters.
    var pdfSinglePageView = new PDFJS.PDFSinglePageViewer({
      container: container,
      id: PAGE_TO_VIEW,
      scale: SCALE,
      defaultViewport: pdfPage.getViewport(SCALE),
      // We can enable text/annotations layers, if needed
      textLayerFactory: new PDFJS.DefaultTextLayerFactory(),
      annotationLayerFactory: new PDFJS.DefaultAnnotationLayerFactory()
    });
    // Associates the actual page with the view, and drawing it
    pdfSinglePageView.setPdfPage(pdfPage);
    return pdfSinglePageView.draw();
  });

Is my approach so far making sense?

Thanks a lot for your time!

Reposting comment with proper formatting.

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Oct 1, 2017

In the components folder, pageviewer.js is an example that uses pdf_page_view.js to display pdf files normally. I need to create an example like singlepageviewer.js that uses pdf_single_page_viewer.js.

Considering that PDFSinglePageViewer implements the same interface as PDFViewer, basing the new example on https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.js would be a much more appropriate starting point.

@pixelexel
Copy link
Contributor

pixelexel commented Oct 2, 2017

Thanks for that advice!
I've submitted a pull request #8989. Please review it and let me know if any changes are to be made.

Edit:
I don't know if I'm missing something here but none of the components examples display anything in the browser at http://localhost:8888/examples/components/{anyfile}.html. Console shows the following errors:

singlepageviewer.html:38 GET http://localhost:8888/node_modules/pdfjs-dist/web/pdf_viewer.css net::ERR_ABORTED
singlepageviewer.html:40 GET http://localhost:8888/node_modules/pdfjs-dist/build/pdf.js net::ERR_ABORTED
singlepageviewer.html:41 GET http://localhost:8888/node_modules/pdfjs-dist/web/pdf_single_page_viewer.js net::ERR_ABORTED
singlepageviewer.js:18 Uncaught ReferenceError: PDFJS is not defined
    at singlepageviewer.js:18

@Snuffleupagus
Copy link
Collaborator

I don't know if I'm missing something here but none of the components examples display anything in the browser at http://localhost:8888/examples/components/{anyfile}.html. Console shows the following errors:

As mentioned in the *.js files of the examples, see e.g. here, did you run gulp dist-install?

@pixelexel
Copy link
Contributor

Got it thanks!
Here's the pull request including all your reviewed changes and according to the Contributing and Squashing Commits wiki : #8990
Thanks a lot for your time!

Snuffleupagus referenced this issue Oct 5, 2017
Added component example for single page viewer
movsb referenced this issue in movsb/pdf.js Jul 14, 2018
Added component example for single page viewer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants