[api-minor] Add support for relative URLs, in both annotations and the outline, by adding a docBaseUrl
parameter to PDFJS.getDocument
(bug 766086)
Note that in `FIREFOX/MOZCENTRAL/CHROME` builds of the standard viewer the `docBaseUrl` parameter will be set by default, since in that case it makes sense to use the current URL as a base. For the `GENERIC` viewer, or the API itself, it doesn't make sense to try and set the `docBaseUrl` by default. However, custom deployments/implementations may still find the parameter useful.
This commit is contained in:
parent
71a781ee5c
commit
d284cfd5eb
11 changed files with 304 additions and 47 deletions
|
@ -789,6 +789,68 @@ describe('api', function() {
|
|||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
|
||||
it('gets annotations containing relative URLs (bug 766086)',
|
||||
function (done) {
|
||||
var url = new URL('../pdfs/bug766086.pdf', window.location).href;
|
||||
|
||||
var defaultLoadingTask = PDFJS.getDocument(url);
|
||||
var defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
|
||||
return pdfDoc.getPage(1).then(function (pdfPage) {
|
||||
return pdfPage.getAnnotations();
|
||||
});
|
||||
});
|
||||
|
||||
var docBaseUrlLoadingTask = PDFJS.getDocument({
|
||||
url: url,
|
||||
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
|
||||
});
|
||||
var docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(
|
||||
function (pdfDoc) {
|
||||
return pdfDoc.getPage(1).then(function (pdfPage) {
|
||||
return pdfPage.getAnnotations();
|
||||
});
|
||||
});
|
||||
|
||||
var invalidDocBaseUrlLoadingTask = PDFJS.getDocument({
|
||||
url: url,
|
||||
docBaseUrl: 'qwerty.pdf',
|
||||
});
|
||||
var invalidDocBaseUrlPromise = invalidDocBaseUrlLoadingTask.promise.then(
|
||||
function (pdfDoc) {
|
||||
return pdfDoc.getPage(1).then(function (pdfPage) {
|
||||
return pdfPage.getAnnotations();
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([defaultPromise, docBaseUrlPromise,
|
||||
invalidDocBaseUrlPromise]).then(function (data) {
|
||||
var defaultAnnotations = data[0];
|
||||
var docBaseUrlAnnotations = data[1];
|
||||
var invalidDocBaseUrlAnnotations = data[2];
|
||||
|
||||
expect(defaultAnnotations[0].url).toBeUndefined();
|
||||
expect(defaultAnnotations[0].unsafeUrl).toEqual(
|
||||
'../../0021/002156/215675E.pdf#nameddest=15');
|
||||
|
||||
expect(docBaseUrlAnnotations[0].url).toEqual(
|
||||
'http://www.example.com/0021/002156/215675E.pdf#nameddest=15');
|
||||
expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
||||
'../../0021/002156/215675E.pdf#nameddest=15');
|
||||
|
||||
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
|
||||
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual(
|
||||
'../../0021/002156/215675E.pdf#nameddest=15');
|
||||
|
||||
defaultLoadingTask.destroy();
|
||||
docBaseUrlLoadingTask.destroy();
|
||||
invalidDocBaseUrlLoadingTask.destroy();
|
||||
done();
|
||||
}).catch(function (reason) {
|
||||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
|
||||
it('gets text content', function (done) {
|
||||
var defaultPromise = page.getTextContent();
|
||||
var parametersPromise = page.getTextContent({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue