Skip to content

Place a SVG into a page #143

Answered by JorjMcKie
Kozaraboy asked this question in Q&A
Feb 10, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Try this approach:

  1. Open the SVG data as a PyMuPDF Document
  2. Convert that document to a (1-page) PDF, open as "source"
  3. Use page.show_pdf_page(rect, source, 0) to place it inside the desired rectangle of the target page.
# open SVG source as a (1-page) PyMuPDF Document:
svg_doc = pymupdf.open("svg", svg_data.encode())  # use the bytes version of svg_data
# convert this to a PDF document
source_data = svg_doc.convert_to_pdf()
source = pymupdf.open("pdf", source_data)
# insert source page into the target rect
page.show_pdf_page(rect, source, 0)

Replies: 1 comment 2 replies

Comment options

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

@Kozaraboy
Comment options

Answer selected by Kozaraboy
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