mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.25k stars 9.96k forks source link

Missing references in internal links in pageviewer example #8188

Closed damiantp closed 7 years ago

damiantp commented 7 years ago

Hi,

I'm trying different components of pdfjs to build my own viewer. My idea is based on the "pageviewer" component example because I want to load only a page at a time. Using this example is working ok, but I don't get the internal links to other pages (although I only load one each time).

I'm using the following pdf (in page 3) as an example: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

I have added two statements to try to mimick what the simpleviewer example is doing with the linkservice, but it's not adding the page reference in the links.

var pdfLinkService = new PDFJS.PDFLinkService(); // <--- ADDED
pdfLinkService.setDocument(pdfDocument, null); // <--- ADDED

(next is the modified version with these two lines)

My question is, is there a configuration that allows the pageviewer example generate links with page references?

Modified versión of "pageviewer" example:

'use strict';

if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
  alert('Please build the pdfjs-dist library using\n' +
        '  `gulp dist`');
}

// The workerSrc property shall be specified.
//
PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';

var DEFAULT_URL = '../../web/pdf_open_parameters.pdf';
var PAGE_TO_VIEW = 3;
var SCALE = 1.0;

var container = document.getElementById('pageContainer');
var pdfLinkService = new PDFJS.PDFLinkService(); // <--- ADDED

// Loading document.
PDFJS.getDocument(DEFAULT_URL).then(function (pdfDocument) {

  pdfLinkService.setDocument(pdfDocument, null); // <--- ADDED

  // Document loaded, retrieving the page.
  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();
  });
});

Link to PDF file (or attach file here): http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

Configuration:

Steps to reproduce the problem:

  1. Open the provided pdf file and go to page 3 that have links to other pages. Links to other pages have the page reference missing, only shows a hash.

What is the expected behavior? (add screenshot) I was expecting to have at least the page parameter in the href attribute, something like "#page=x"

What went wrong? (add screenshot)

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):

yurydelendik commented 7 years ago

We need to add something like PDFSinglePageViewer which will implement interface similar to what PDFViewer has. There are few methods needed to be implemented to properly work for link and find services. Marking as beginner bug since it's just identifying which interface needs to be extracted from PDFViewer and implementing it in the new class (e.g. PDFSinglePageViewer). The PDFSinglePageViewer can/will be use for presentation mode.

nish17 commented 7 years ago

When I try to open the internal links in the given pdf (http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf), It works perfectly fine. Internal links are working as expected.

yurydelendik commented 7 years ago

@nish17 does it work in the https://github.com/mozilla/pdf.js/blob/master/examples/components/pageviewer.html app?

nish17 commented 7 years ago

Nope, Nothing shows up.

samurdhilbk commented 7 years ago

@yurydelendik I have been working on this issue. I added similar capabilities for linkService and annotations already present in the PDFViewer class to the PDFPageView class. Although the resulting code builds without problem, the original issue still remains. Any directions?

timvandermeij commented 7 years ago

Closing since this is fixed by #8724. The components example is tracked in a new issue.