Skip to content

Render pages concurrently #315

Closed Answered by mara004
naourass asked this question in Q&A
May 26, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Yeah it is. Take a look at src/pypdfium2/_cli/render.py for a sample implementation. Key notes:

  • pdfium/ctypes object handles can't be transferred across processes; instead you have to create them in workers. (i.e. pass filepath/input and page indices instead of PdfDocument or PdfPage objects)
  • Use a multiprocessing initializer and a global variable to set up process-scope objects (e.g. the PdfDocument).
  • Do all post-processing/saving (or whatever uses the bitmap) in workers. Do NOT transfer bitmaps back to the main process (this was a historical fault in pypdfium2).
  • Do not use the fork multiprocessing strategy, it has unpredictable stability issues. Use spawn or maybe forkserver instead.
  • F…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by mara004
Comment options

You must be logged in to vote
1 reply
@mara004
Comment options

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