Last active
October 21, 2023 11:00
-
-
Save tmr232/9d7f32a2f4316c809947187ced2bff53 to your computer and use it in GitHub Desktop.
Edge enables all PDF layers for printing
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
""" | |
Create a PDF with multiple layers to demonstrate issues with MS Edge printing. | |
See https://github.com/pymupdf/PyMuPDF-Utilities/blob/master/jupyter-notebooks/optional-content.ipynb for reference. | |
""" | |
import fitz # PyMuPDF | |
def main(): | |
doc = fitz.open() | |
page = doc.new_page(height=400, width=500) | |
text_display = "This is the text I want to print." | |
text_print = "But this is the text that gets printed." | |
oc_display = doc.add_ocg("display", on=True) | |
oc_print = doc.add_ocg("print", on=False) | |
page.insert_textbox( | |
rect, | |
text_display, | |
fontsize=12, | |
oc=oc_display, | |
) | |
rect = fitz.Rect(50, 50, 400, 300) | |
page.draw_rect( | |
rect + (-5, -5, 5, 5), | |
fill=fitz.pdfcolor["white"], | |
color=fitz.pdfcolor["white"], | |
oc=oc_print, | |
) | |
page.insert_textbox( | |
rect, | |
text_print, | |
fontsize=12, | |
oc=oc_print, | |
) | |
doc.save("test.pdf") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment