How can i create multiple print tasks, one per record, and not a global one, when using mailing assistant?

Our printer has a staple unit. I can’t use it with a global print task (a merged document with all records enclosed).

Made a macro to do the job :

sub PrintMultipleJobs

’ Macro fonctionnelle avec Libreoffice 5
’ destinée à générer une tâche d’impression par plage de pages
’ afin d’utiliser les options de finition - agrafage ou pliage
’ Il est nécessaire de paramétrer l’imprimante par défaut avec tous les réglages nécessaires.

Dim oDoc As Object
Dim oDocView As Object
Dim iCurPage As Integer
Dim TotalPages As Integer
Dim increment as integer
Dim index as integer

oDoc = ThisComponent
oDocView = oDoc.getCurrentController()
TotalPages = getPageCount(oDoc)

’ increment est le nombre de pages du modèle de publipostage
’ a personnaliser, donc
increment = 3

index = 1
numofprintjobs = getPageCount(oDoc)/increment
msgbox "Nombre de tâches à générer " & numofprintjobs

Dim mPrintOpts(0) As New com.sun.star.beans.PropertyValue

for i = 1 to numofprintjobs step 1
mPrintOpts(0).Name = “Pages”
mPrintOpts(0).Value = “” & index & “-” & (index + increment -1) & “”
oDoc.print(mPrintOpts())
index = index + increment
next

msgbox “ok”

end sub

Function getPageCount(oDoc)
oProps = oDoc.getDocumentProperties()
REM or pseudo-property: oProps = oDoc.DocumentProperties
aStats = oProps.DocumentStatistics ’ true property
REM oDoc.getDocumentStatistics() is not a valid method call

REM Loop through the array of c.s.s.beans.NamedValue
for i = uBound(aStats) to 0 step -1
x = aStats(i)
if x.Name = “PageCount” then exit for
next
getPageCount = 0
if i > -1 then getPageCount = x.Value
End Function