question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative links did not enable by setting the docBaseUrl

See original GitHub issue

Hi,

I am new to pdf.js and managed to set up the pdf.js and pdf_viewer.js using the following code. My intention is to enable internal links and work with PDF files.

var DEFAULT_URL = "../learning/test.pdf";
var DOC_BASE_URL = "D:/workspace/repos/github/pdf.js/examples/learning";
// Loading document.
var loadingTask = pdfjsLib.getDocument({
  url: DEFAULT_URL,
  docBaseUrl: DOC_BASE_URL,
});
loadingTask.promise.then(function (pdfDocument) {
  pdfViewer.setDocument(pdfDocument);
  pdfLinkService.setDocument(pdfDocument, null);
  debugger;
});

The set up was a success. But the problem is, it did not enable the internal links. Could someone help me to enable the internal links using the docBaseUrl, please?

Also, I went through the following links. But could not get a proper idea about the fix.

Relative links to pdfs not working with hosted pdf.js and demo viewer Hyperlinks not working Add support for relative URLs…

NOTE: I know this is a place to report errors. I asked the related question in the available chat room at https://chat.mozilla.org/. But no one answered the question. That is why I am posting the question here. Please be kind enough.

Thank you very much. Shan

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timvandermeijcommented, Oct 20, 2020

You’ll have to provide a runnable example so we can take a look, because as indicated in the issue template just code snippets don’t help to be able to debug this. Moreover, start by checking if the example at https://github.com/mozilla/pdf.js/blob/master/examples/components/singlepageviewer.js works. If so, you can check what the differences are with your code. Finally, when opening an issue it’s important to provide all details as asked for in the issue template.

0reactions
ishanudacommented, Oct 22, 2020

Dear sir,

Thank you for your explanation. I think now I clearly understand the way docBaseUrl works.

However, I notice that the docBaseUrl should end with a forward slash to the root folder in order to resolve the links.

e.g. var DOC_BASE_URL = "http://127.0.0.1:5500/examples/";

Also, I would like to know, How to access the underlying pdfjsLib or any other related services to set the docBaseUrl or manipulate the PDF document (e.g. getJavaScript() etc.) when implementing the built-in web viewer?

Thank you very much Shan

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using pdf.js to render a PDF but it doesn't work and I don't get ...
Notice that cMapUrl should be a relative or absolute path to the cmap folder. PDFJS often needs these files to actually interpret a...
Read more >
Relative Links from PowerPoint | Adobe Acrobat
I am creating relative links to PDF files from a PowerPoint presentation, then using PowerPoint Save As PDF to create the "master" PDF...
Read more >
JSDoc: Module: pdfjsLib
The base URL of the document, used when attempting to recover valid absolute URLs for annotations, and outline items, that (incorrectly) only specify...
Read more >
JSDoc: Source: display/api.js
When range requests are enabled PDF.js will automatically keep; * fetching more data even if it isn't needed to display the current page....
Read more >
PDF.js - Browse /v1.7.225 at SourceForge.net
SourceForge is not affiliated with PDF.js. ... [#7717] Explain double-click behaviour on tool tip [#7689] [api-minor] Add support for relative URLs, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found