-
when i use my own font file to insert_htmlbox like the link below. but if document have many pages and i need do the insert_htmlbox on every page in a for loop, memory usage increse really fast, and finally cause the program crash. i assume the Archive object is the reason, beacause when i dont use my own font, there is no problem. doc = pymupdf.open("test.pdf")
arch = pymupdf.Archive("./fonts")
css = """
@font-face {font-family: user; src: url(SourceHanSrif-Bold.otf);}
* {font-family: user, sans-serif}
"""
for page in doc:
page.insert_htmlbox(rect, text, css=css, archive=arch)
doc.subset_fonts(verbose=True) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The reason is probably the crazy size of that font (24 MB), not the archive. for page in doc:
page.insert_htmlbox(rect, text, css=css, archive=arch)
page = None
pymupdf.TOOLS.store_shrink(100) If this does not help and the inserted text is the same on each page, there may be other options for reducing memory usage and also speeding up things. |
Beta Was this translation helpful? Give feedback.
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.
insert_htmlbox
on that temporary pagepage.show_pdf_page(rect, temp, 0)
This will use no additional memory each time and also be very much faster!