forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[marionette] Implement pageRanges support.
This allows printing only specified page ranges. We take them in the form ["1-2", 4, "5-"] and convert to a flat array of the form [1,2,4,4,5,2147483647], which is appropriate for nsIPrintSettings. Testing relies on the fact that wpt vendored pdf.js for print reftests; using the same mechaism we can ensure the correct pages were printed. Differential Revision: https://phabricator.services.mozilla.com/D97600 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1678347 gecko-commit: b709a9d0378a70877df4a17def06ae792ee2dcf2 gecko-reviewers: webdriver-reviewers, whimboo
- Loading branch information
1 parent
d55ae32
commit 399ddc8
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def load_pdf_document(session, inline, pdf_data): | ||
"""Load a PDF document in the browser using pdf.js""" | ||
session.url = inline(""" | ||
<!doctype html> | ||
<script src="/_pdf_js/pdf.js"></script> | ||
<canvas></canvas> | ||
<script> | ||
async function getText() { | ||
pages = []; | ||
let loadingTask = pdfjsLib.getDocument({data: atob("%s")}); | ||
let pdf = await loadingTask.promise; | ||
for (let pageNumber=1; pageNumber<=pdf.numPages; pageNumber++) { | ||
let page = await pdf.getPage(pageNumber); | ||
textContent = await page.getTextContent() | ||
text = textContent.items.map(x => x.str).join(""); | ||
pages.push(text); | ||
} | ||
return pages | ||
} | ||
</script> | ||
""" % pdf_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters