How To Convert Microsoft Word DOC to PDF Without Losing Formatting in Java

Hi,
We are using Aspose Word cloud doc to pdf conversion but the output PDF File has changed format and margin. We want to append word files, convert them into pdf and get them as byte[] or stream. If there is any better solution kindly provide. following is the code that i am using:

DownloadFileRequest downloadFileRequest = new DownloadFileRequest(folder + fileName, storage, null);
byte[] downloadedWord = Files.readAllBytes(wordsApi.downloadFile(downloadFileRequest).toPath());

SaveOptionsData optionsData = new SaveOptionsData();
optionsData.setSaveFormat(“pdf”);
optionsData.setFileName(“output.pdf”);

SaveAsOnlineRequest saveAsOnlineRequest = new SaveAsOnlineRequest(downloadedWord, optionsData, null, null, null);
SaveAsOnlineResponse saveAsOnlineResponse = wordsApi.saveAsOnline(saveAsOnlineRequest);
byte[] outputPDF = saveAsOnlineResponse.getDocument();

This is how my word file is:
image.png (10.2 KB)

This is output pdf i am getting:
image.png (8.1 KB)

I can share my credentials and the filename if required. Looking forward to your positive response.

@ahmedtariq3

We used the latest version of Aspose.Words Cloud SDK for Java to Convert Microsoft Word DOC to PDF without any formatting issue. Please share your input Word document with us. We will investigate the issue and will share our findings with you.