I am using pymupdf to alter a pdf. I can insert text without issue. When I attempt to insert an image it does not show up. No error msgs. On a blank pdf, the png image will show up. The pdf I want to insert the image into was made in Canva if that’s relevant. I should say the same results happen using both pymupdf.rect and fitz.rect.
I have tried multiple import versions with success on the blank pdf page. I’ve tried both filename and streaming as the argument for how to insert the image. Successful again on a blank pdf but not on my stylized pdf. I have inserted text into the pdf and the same page I want the image to try that. I’ve deleted other images off of the pdf page in case that was causing the issue.
import pymupdf
import os
def create_pdf(bar_chart):
base_pdf_path = "C:\PATHTO\base_pdf.pdf"
base_pdf = pymupdf.open(base_pdf_path)
#pg.2 bar chart
fourth_page = base_pdf[3]
image_rectangle = pymupdf.Rect(50,20,550,320)
fourth_page.insert_image(image_rectangle, filename=bar_chart)
output_pdf_path = "C:\PATHTO\output_pdf.pdf"
base_pdf.save(output_pdf_path, garbage=4)
base_pdf.close()
create_pdf(path_to_bar_chart)