MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / scrub

Method scrub

src/__init__.py:6563–6716  ·  view source on GitHub ↗
(
            doc: 'Document',
            attached_files: bool = True,
            clean_pages: bool = True,
            embedded_files: bool = True,
            hidden_text: bool = True,
            javascript: bool = True,
            metadata: bool = True,
            redactions: bool = True,
            redact_images: int = 0,
            remove_links: bool = True,
            reset_fields: bool = True,
            reset_responses: bool = True,
            thumbnails: bool = True,
            xml_metadata: bool = True,
            )

Source from the content-addressed store, hash-verified

6561 # Acrobat 'sanitize' function
6562 # ------------------------------------------------------------------------------
6563 def scrub(
6564 doc: 'Document',
6565 attached_files: bool = True,
6566 clean_pages: bool = True,
6567 embedded_files: bool = True,
6568 hidden_text: bool = True,
6569 javascript: bool = True,
6570 metadata: bool = True,
6571 redactions: bool = True,
6572 redact_images: int = 0,
6573 remove_links: bool = True,
6574 reset_fields: bool = True,
6575 reset_responses: bool = True,
6576 thumbnails: bool = True,
6577 xml_metadata: bool = True,
6578 ) -> None:
6579
6580 def remove_hidden(cont_lines):
6581 """Remove hidden text from a PDF page.
6582
6583 Args:
6584 cont_lines: list of lines with /Contents content. Should have status
6585 from after page.cleanContents().
6586
6587 Returns:
6588 List of /Contents lines from which hidden text has been removed.
6589
6590 Notes:
6591 The input must have been created after the page's /Contents object(s)
6592 have been cleaned with page.cleanContents(). This ensures a standard
6593 formatting: one command per line, single spaces between operators.
6594 This allows for drastic simplification of this code.
6595 """
6596 out_lines = [] # will return this
6597 in_text = False # indicate if within BT/ET object
6598 suppress = False # indicate text suppression active
6599 make_return = False
6600 for line in cont_lines:
6601 if line == b"BT": # start of text object
6602 in_text = True # switch on
6603 out_lines.append(line) # output it
6604 continue
6605 if line == b"ET": # end of text object
6606 in_text = False # switch off
6607 out_lines.append(line) # output it
6608 continue
6609 if line == b"3 Tr": # text suppression operator
6610 suppress = True # switch on
6611 make_return = True
6612 continue
6613 if line[-2:] == b"Tr" and line[0] != b"3":
6614 suppress = False # text rendering changed
6615 out_lines.append(line)
6616 continue
6617 if line == b"Q": # unstack command also switches off
6618 suppress = False
6619 out_lines.append(line)
6620 continue

Callers 2

test_textbox3Function · 0.80
test_4590Function · 0.80

Calls 15

remove_hiddenFunction · 0.85
set_metadataMethod · 0.80
widgetsMethod · 0.80
get_linksMethod · 0.80
delete_linkMethod · 0.80
annotsMethod · 0.80
update_fileMethod · 0.80
delete_responsesMethod · 0.80
apply_redactionsMethod · 0.80
get_contentsMethod · 0.80
xref_streamMethod · 0.80
update_streamMethod · 0.80

Tested by 2

test_textbox3Function · 0.64
test_4590Function · 0.64