mozilla / pdf.js

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

Relative link in pdf to another pdf not working #6616

Closed eaxle closed 7 years ago

eaxle commented 8 years ago

I have a master PDF document that has some relative links to other PDF documents... When I open it locally in Adobe Acrobat Reader, the links works... When I try to open the master document in pdfjs, the links points to itself with '#page=1'.Inspect element shows:(title="" href="#page=1" class="internalLink") for anchor tag

.In fact all the links have same href value.The master pdf file is single page file. In pdf.worker.js,inside LinkAnnotationClosure() function ,inside else if (linkType === 'GoToR') .. I console.log(action.get('F').get('F'))the url when (isDict(urlDict)==true I can see the pdf document name that I want to open.I tried https://github.com/mozilla/pdf.js/issues/3572 and https://github.com/mozilla/pdf.js/issues/1778 in pdf.worker.js but it didn't help.The link Type are Launch and GoToR.The url value goes into invalid url in the code

eaxle commented 8 years ago

turns out if (!isValidUrl(url, true)) { url = ''; } solved my problem

Rob--W commented 8 years ago

Please share a PDF file that shows the problem.

eaxle commented 8 years ago

@Rob--W I am sorry, I am not allowed.But there are pdfs with relative links to other pdfs in internet.

eaxle commented 8 years ago

the value to relative links was false in pdf.worker.js . I set the value to true .This solved my problem

yurydelendik commented 8 years ago

Be careful, the change you proposing might cause cross-site scripting attacks of non-trusted pdfs are served.

timvandermeij commented 8 years ago

It is very hard to fix this issue if no example PDF file is provided, hence I'm closing this as incomplete until a file is provided and there is a possible solution that will have less security implications.

eaxle commented 8 years ago

Untitled.pdf master.pdf I tried to replicate the files I was provided and these are the files I could come near to replicate the files.The code That solved my problem is

       else if(linkType === 'Launch'){
      var urlDict = action.get('F');
      if (isDict(urlDict)) {
          // We assume that the 'url' is a Filspec dictionary
          // and fetch the url without checking any further
          url = urlDict.get('F') || '';
          console.log(url)
      }
      if (!isValidUrl(url, true)) {
          url = '';
      }
      var checkIfPdf=url.split(".");
      if(checkIfPdf[checkIfPdf.length-1]=='pdf'){
          url="?file="+url;
      }
      data.url = url;

      data.dest = action.get('D');

  }

and changes were done in :-

     else if (linkType === 'GoToR') {
    var urlDict = action.get('F');
    if (isDict(urlDict)) {
      // We assume that the 'url' is a Filspec dictionary
      // and fetch the url without checking any further
      url = urlDict.get('F') || '';
    }
      //console.log(url)

    // TODO: pdf reference says that GoToR
    // can also have 'NewWindow' attribute
    if (!isValidUrl(url, true)) {
      url = '';
    }
      var checkIfPdf=url.split(".");
      if(checkIfPdf[checkIfPdf.length-1]=='pdf'){
          url="?file="+url;
      }
    data.url = url;

    data.dest = action.get('D');
  }
Rob--W commented 8 years ago

Thanks for the information, re-opening.

ghost commented 8 years ago

I believe this file has the same problem:

http://webarchive.nationalarchives.gov.uk/20120809191124/http://www.bahamousainquiry.org/f_report/vol%20i/volume%20i.pdf

(any link on the main index gives me 'Warning: unrecognized link type: Launch', while the downloaded version does attempt to load the linked files, failing only because they aren't present locally)