Officer in R not exporting image file to desired location or slide in a PowerPoint

47 Views Asked by At

I'm using the below test code to export a png file into powerpoint using officer (I'm new to using this package). The below code partially works, however the image does not appear in the location or slide specified. Additionally, I would like the image to appear in its original size, the exported image is currently slightly 'squashed'. For some reason, the below code adds empty title text boxes to the same presentation slide as the exported image (not a desired outcome).

directory_factsheet = "factsheets/MCU/"
directory_plots = "plots/sharpe_fixed_gauge/"

# Define the paths to your existing image file and the PowerPoint presentation
image_name = "2023_Q3_MCU_Risk_adjusted_return_peer_group_rankings_R_Rathbone_Total_Return_Portfolio.png"
image_path = paste(directory_plots ,image_name,sep="")
pptx_name = "2023_Q3_MCU_R_Rathbone_Total_Return_Portfolio.pptx"
pptx_path = paste(directory_factsheet,pptx_name,sep="")

# Read the existing PowerPoint presentation
ppt = read_pptx(pptx_path)

# Add the image to the PowerPoint slide
ppt_v2 = ppt %>%
  ph_with(value=external_img(src=image_path, guess_size = FALSE), 
          location = ph_location(left = 1.08, top = 5.76),
          slide = 1)

# Save the modified PowerPoint presentation
output_pptx = paste(directory_factsheet, pptx_name, sep = "")
print(ppt_v2, target = output_pptx)
0

There are 0 best solutions below