How correct image alignment while exporting multiple charts on a spreadsheet using Macros

Hi there,
I am trying to export all charts on multiple sheet within my spreadsheet.
I’ve looked some examples online to came up with a code that extracts all graphs within my file as PNGs.
But I may be missing something, because every time I run this macro, some images are generated misaligned (and not the same, sometimes images are correct).
This code is simple, but I don’t what might be causing it.
Could anyone help me solve this?

Thanks in advance


Sub ExportGraphs
oDoc = ThisComponent
Dim oSheet As Object
Dim eSheets As Object

Dim args(1) as new com.sun.star.beans.PropertyValue

gef = CreateUnoService("com.sun.star.drawing.GraphicExportFilter")

eSheets = oDoc.getSheets.createEnumeration()
 
While eSheets.hasMoreElements
    oSheet = eSheets.nextElement()
    oDrawPage = oSheet.getDrawPage()
    iLimit = oDrawPage.getCount() -1
    
    For index = 0 to iLimit
        oDraw = oDrawPage.getByIndex(index)
        	
		args(0).Name = "URL"
		args(0).Value = "file:///home/user_name/Desktop/graphs/graph_" & oSheet.getName & "_" & index+1 & ".png"
		args(1).Name = "MimeType"
		args(1).Value = "image/png"

		gef.setSourceDocument(oDraw)
		gef.filter(args)

	Next
Wend

End Sub

Dupe