1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #6236 from Rob--W/print-javascript-action

Detect scripted auto-print requests
This commit is contained in:
Tim van der Meij 2015-07-25 19:42:31 +02:00
commit d08895d659
6 changed files with 124 additions and 24 deletions

View file

@ -146,4 +146,6 @@
!issue6068.pdf
!issue6081.pdf
!issue6069.pdf
!issue6106.pdf
!bug1001080.pdf
!issue6108.pdf

BIN
test/pdfs/bug1001080.pdf Normal file

Binary file not shown.

70
test/pdfs/issue6106.pdf Normal file
View file

@ -0,0 +1,70 @@
%PDF-1.4
% To manually verify that PDF.js works as expected, open this PDF file with
% PDF.js and check whether the browser attempts to print the PDF.
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/OpenAction 3 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Count 1
/Kids [4 0 R]
>>
endobj
3 0 obj
<<
/Type /Action
/S /JavaScript
% This is a verbatim copy from a PDF generated by Google Drive (20 July 2015)
/JS (this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)
>>
endobj
4 0 obj
<<
/Parent 2 0 R
/Contents 6 0 R
/Type /Page
/Resources 5 0 R
/MediaBox [0 0 400 200]
>>
endobj
5 0 obj
<<
/Font
<<
/F1
<<
/Type /Font
/Subtype /Type1
/BaseFont /Arial
>>
>>
>>
endobj
6 0 obj
<</Length 58>>
stream
BT/F1 20 Tf 70 88 Td(Should trigger a print action.) Tj ET
endstream
endobj
xref
0 7
0000000000 65535 f
0000000151 00000 n
0000000218 00000 n
0000000275 00000 n
0000000467 00000 n
0000000571 00000 n
0000000685 00000 n
trailer
<<
/Root 1 0 R
/Size 7
>>
startxref
791
%%EOF

View file

@ -147,6 +147,32 @@ describe('api', function() {
expect(data).toEqual([]);
});
});
// Keep this in sync with the pattern in viewer.js. The pattern is used to
// detect whether or not to automatically start printing.
var viewerPrintRegExp = /\bprint\s*\(/;
it('gets javascript with printing instructions (Print action)', function() {
// PDF document with "Print" Named action in OpenAction
var pdfUrl = combineUrl(window.location.href, '../pdfs/bug1001080.pdf');
var promise = PDFJS.getDocument(pdfUrl).then(function(doc) {
return doc.getJavaScript();
});
waitsForPromiseResolved(promise, function (data) {
expect(data).toEqual(['print({});']);
expect(data[0]).toMatch(viewerPrintRegExp);
});
});
it('gets javascript with printing instructions (JS action)', function() {
// PDF document with "JavaScript" action in OpenAction
var pdfUrl = combineUrl(window.location.href, '../pdfs/issue6106.pdf');
var promise = PDFJS.getDocument(pdfUrl).then(function(doc) {
return doc.getJavaScript();
});
waitsForPromiseResolved(promise, function (data) {
expect(data).toEqual(
['this.print({bUI:true,bSilent:false,bShrinkToFit:true});']);
expect(data[0]).toMatch(viewerPrintRegExp);
});
});
it('gets outline', function() {
var promise = doc.getOutline();
waitsForPromiseResolved(promise, function(outline) {