How do I delete a page a docx, through the libreoffice cli?

For some reason the macro isn’t running at all in --hidden mode. Maybe the cursor commands can only work in full gui mode? soffice --hidden macro:///Standard.Module1.del doc0.docx seems to have no effect.

For example, let’s transform oldDoc.docx → newDoc.docx

Sub ToOnePage
  Dim doc, cursor, pageCount As Long
  Dim props2(0) As New com.sun.star.beans.PropertyValue 
  Dim props(0) As New com.sun.star.beans.PropertyValue
  props(0).Name="Hidden"
  props(0).Value=True
  doc = StarDesktop.LoadComponentFromUrl(ConvertToUrl("C:\Temp\oldDoc.docx"),"_default",0, props)  
  pageCount = doc.CurrentController.PageCount
  cursor = doc.CurrentController.getViewCursor()
  If cursor.jumpToNextPage() Then
    cursor.gotoEnd(true)
    cursor.setString("")
  End If

  props2(0).Name="FilterName"
  props2(0).Value="MS Word 2007 XML"
  doc.storeToURL(ConvertToUrl("C:\Temp\newDoc.docx"), props2)
  doc.close(true)
End Sub
1 Like

I can not even begin to explain how much agony you have saved me. Thank you so much for your help.

I just commented on @mikekaganski 's approaches. :slightly_smiling_face: