Skip to content

reduce Archive object memory usage #3570

Answered by JorjMcKie
YYTB asked this question in Q&A
Discussion options

You must be logged in to vote

Just tested my own suggestion: It will not help!

So, depending on the assumption that you indeed are inserting the same text box on each page, here is a suggestion.

  1. Make a temporary PDF with one page having the dimension of the rectangle.
  2. insert_htmlbox on that temporary page
  3. For the pages in your real PDF, execute page.show_pdf_page(rect, temp, 0)

This will use no additional memory each time and also be very much faster!

rect = pymupdf.Rect(100, 100, 300, 300)

# Insert the text on a temporary PDF page with suitable size
temp = pymupdf.open()
tpage = temp.new_page(width=rect.width, height=rect.height)
tpage.insert_htmlbox(tpage.rect, text, css=css, archive=arch)

doc = pymupdf.open(...)  

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@YYTB
Comment options

@JorjMcKie
Comment options

Answer selected by YYTB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants