Using this InputStream, you can convert docx to pdf. Apache POI library can be used for conversion. Here is a related topic on Stackoverflow.
As you got the pdf document, you can save it to file storage using the FileLoader.saveStream() method.
More information about managing files in CUBA can be found in the documentation.