Relative links did not enable by setting the docBaseUrl
See original GitHub issueHi,
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:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
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.
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 thedocBaseUrl
or manipulate the PDF document (e.g.getJavaScript()
etc.) when implementing the built-in web viewer?Thank you very much Shan