Skip to content

Instantly share code, notes, and snippets.

@ivan
Created January 21, 2019 01:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/4fbc206a27b102f58200ddcf7b300b05 to your computer and use it in GitHub Desktop.
Save ivan/4fbc206a27b102f58200ddcf7b300b05 to your computer and use it in GitHub Desktop.
Chromium: ignore PDF permissions that restrict copying text and printing
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index 8c3a4691ca5b..1bf4c4eabb7c 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -2299,35 +2299,7 @@ std::string PDFiumEngine::GetLinkAtPosition(const pp::Point& point) {
}
bool PDFiumEngine::HasPermission(DocumentPermission permission) const {
- // PDF 1.7 spec, section 3.5.2 says: "If the revision number is 2 or greater,
- // the operations to which user access can be controlled are as follows: ..."
- //
- // Thus for revision numbers less than 2, permissions are ignored and this
- // always returns true.
- if (permissions_handler_revision_ < 2)
- return true;
-
- // Handle high quality printing permission separately for security handler
- // revision 3+. See table 3.20 in the PDF 1.7 spec.
- if (permission == PERMISSION_PRINT_HIGH_QUALITY &&
- permissions_handler_revision_ >= 3) {
- return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 &&
- (permissions_ & kPDFPermissionPrintHighQualityMask) != 0;
- }
-
- switch (permission) {
- case PERMISSION_COPY:
- return (permissions_ & kPDFPermissionCopyMask) != 0;
- case PERMISSION_COPY_ACCESSIBLE:
- return (permissions_ & kPDFPermissionCopyAccessibleMask) != 0;
- case PERMISSION_PRINT_LOW_QUALITY:
- case PERMISSION_PRINT_HIGH_QUALITY:
- // With security handler revision 2 rules, check the same bit for high
- // and low quality. See table 3.20 in the PDF 1.7 spec.
- return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0;
- default:
- return true;
- }
+ return true;
}
void PDFiumEngine::SelectAll() {
@ivan
Copy link
Author

ivan commented Jan 21, 2019

Chromium has an annoying feature that Firefox does not have: it respects text-copying restrictions found in many PDF files (sample), silently failing to put text in the clipboard when attempting to copy text from such files. These restrictions aren't even fully implemented inside Chromium: the Print Preview for a PDF allows copying all text. Because this protection is so ineffective and widely ignored in another browser, I think it is just an annoyance that should be patched out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment