mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
Merge pull request #6988 from timvandermeij/fileattachment-annotation
Implement support for FileAttachment annotations
This commit is contained in:
commit
41efb92d3a
19 changed files with 222 additions and 34 deletions
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -217,3 +217,4 @@
|
|||
!annotation-strikeout.pdf
|
||||
!annotation-squiggly.pdf
|
||||
!annotation-highlight.pdf
|
||||
!annotation-fileattachment.pdf
|
||||
|
|
BIN
test/pdfs/annotation-fileattachment.pdf
Normal file
BIN
test/pdfs/annotation-fileattachment.pdf
Normal file
Binary file not shown.
|
@ -2773,6 +2773,13 @@
|
|||
"type": "eq",
|
||||
"annotations": true
|
||||
},
|
||||
{ "id": "annotation-fileattachment",
|
||||
"file": "pdfs/annotation-fileattachment.pdf",
|
||||
"md5": "d20ecee4b53c81b2dd44c8715a1b4a83",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"annotations": true
|
||||
},
|
||||
{ "id": "issue6108",
|
||||
"file": "pdfs/issue6108.pdf",
|
||||
"md5": "8961cb55149495989a80bf0487e0f076",
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
/* globals expect, it, describe, Dict, Name, Annotation, AnnotationBorderStyle,
|
||||
AnnotationBorderStyleType, AnnotationFlag */
|
||||
AnnotationBorderStyleType, AnnotationFlag, PDFJS, combineUrl,
|
||||
waitsFor, beforeEach, afterEach, stringToBytes */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('Annotation layer', function() {
|
||||
function waitsForPromiseResolved(promise, successCallback) {
|
||||
var resolved = false;
|
||||
promise.then(function(val) {
|
||||
resolved = true;
|
||||
successCallback(val);
|
||||
},
|
||||
function(error) {
|
||||
// Shouldn't get here.
|
||||
expect(error).toEqual('the promise should not have been rejected');
|
||||
});
|
||||
waitsFor(function() {
|
||||
return resolved;
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
describe('Annotation', function() {
|
||||
it('should set and get flags', function() {
|
||||
var dict = new Dict();
|
||||
|
@ -172,4 +188,33 @@ describe('Annotation layer', function() {
|
|||
expect(borderStyle.verticalCornerRadius).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('FileAttachmentAnnotation', function() {
|
||||
var loadingTask;
|
||||
var annotations;
|
||||
|
||||
beforeEach(function() {
|
||||
var pdfUrl = combineUrl(window.location.href,
|
||||
'../pdfs/annotation-fileattachment.pdf');
|
||||
loadingTask = PDFJS.getDocument(pdfUrl);
|
||||
waitsForPromiseResolved(loadingTask.promise, function(pdfDocument) {
|
||||
waitsForPromiseResolved(pdfDocument.getPage(1), function(pdfPage) {
|
||||
waitsForPromiseResolved(pdfPage.getAnnotations(),
|
||||
function (pdfAnnotations) {
|
||||
annotations = pdfAnnotations;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
loadingTask.destroy();
|
||||
});
|
||||
|
||||
it('should correctly parse a file attachment', function() {
|
||||
var annotation = annotations[0];
|
||||
expect(annotation.file.filename).toEqual('Test.txt');
|
||||
expect(annotation.file.content).toEqual(stringToBytes('Test attachment'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
/* globals expect, it, describe, combineUrl, Dict, isDict, Name, PDFJS,
|
||||
stringToPDFString, isExternalLinkTargetSet, LinkTarget,
|
||||
removeNullCharacters */
|
||||
removeNullCharacters, getFilenameFromUrl */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('util', function() {
|
||||
describe('getFilenameFromUrl', function() {
|
||||
it('should get the filename from an absolute URL', function() {
|
||||
var url = 'http://server.org/filename.pdf';
|
||||
var result = getFilenameFromUrl(url);
|
||||
var expected = 'filename.pdf';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should get the filename from a relative URL', function() {
|
||||
var url = '../../filename.pdf';
|
||||
var result = getFilenameFromUrl(url);
|
||||
var expected = 'filename.pdf';
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('combineUrl', function() {
|
||||
it('absolute url with protocol stays as is', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue