I am using --headless mode and want to close the document so i can load another

I am using --headless mode and want to close the document.

Basically I am wanting to extract the text from the document, and take a preview image of the doc.

So for example a docx would be loaded, image taken, txt file written, then document closed so another document can be loaded in its place and the process repeated.

On Commandline youre allowed to use Globbing-syntax to convert in batch, something like:

soffice --convert-to "txt:Text (encoded):UTF8" *.docx 

to convert any .docx-file from inside $pwd to Plain-Text-files.
Actually I don’t know what you do by …image taken… ??

I suppose that OP wants to also convert to an image format (like e.g. PNG).
Also, globbing only works this way under a *nix system - it will fail on Windows. You need to use shell’s for.