Controlling output pdf size when converting via command line

I am writing a webapp and as part of it, I use libreoffice in headless mode to convert docx and pptx files to pdfs (for future processing). How can I set the page size of the output pdf to be the same as the size of the input docx/pptx? At the moment the output pdf is sometimes a different size, leading to the output pdf having some images cropped and a differing number of pages from the original image.

For reference, this is the command I am currently using:
libreoffice --headless --convert-to pdf:writer_pdf_Export --outdir output_dir input_path

Could I maybe run a command to get the page size of the input pdf and then set the output pdf to have this same page size?

Any help is much appreciated. Thanks!

The crucial point may be to find out a reason for “sometimes”. Can you collect this files?

tdf#162412

Command line conversion is intended to create as close representation of the source as possible. All page sizes must be as in the DOCX/PPTX. If that’s not so, this is a bug, which needs to be filed, accompanied by a problematic DOCX/PPTX sample (of course, given that your problem is reproducible with current versions of LibreOffice).