Convert Microsoft Word to PDF in C# using Aspose.Words REST API has missing images and highlighting issue

Hi,

I am using the code snippet, to convert pdf to doc however the image and highlighting is missing

WordsApi wordsApi = new WordsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

 // Set input file name
 String fileName = "Rendering.docx";
 String storage = null;
 String folder = null;

 Com.Aspose.Words.Model.SaveOptionsData body = new Com.Aspose.Words.Model.SaveOptionsData();
 body.SaveFormat = "pdf";
 body.FileName = "output.pdf";


 try
 {
     
     // Upload file to aspose cloud storage
     storageApi.PutCreate(fileName, null, null, System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

     // Invoke Aspose.Words Cloud SDK API to convert words document to required format
     SaveResponse apiResponse = wordsApi.PostDocumentSaveAs(fileName, storage, folder, body);

     if (apiResponse != null && apiResponse.Status.Equals("OK"))
     {
         Console.WriteLine("doc:" + apiResponse.SaveResult.DestDocument.Href);
         //Console.ReadKey();
     }
 }
 catch (Exception ex)
 {
     System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
 }

}

@seanfitz

Thank you for contacting Aspose Support.

The example you shared is converting Docx to PDF not PDF to Docx. I tested PostDocumentSaveAs API and it successfully converts the Docx file (containing Image and Highlighted text) to PDF. I have attached the Input and Output files for your consideration.

Source Files: Source Files.zip (55.9 KB)
Output Files: Output Files.zip (127.6 KB)

If you want to convert PDF document to Docx, please try ConvertPdfToOtherFormat or ConvertPdfToOtherFormatWithoutStorage example.

1 Like

@seanfitz

We would like to update you that we have made some breaking changes in the latest API Version V4.0 of Aspose.Words Cloud. In this release, we have introduced native storage API methods and changed PUT methods to POST (and vice versa). Now, all idempotent methods are PUT and non-idempotent ones are POST.

Please check sample .NET code for uploading DOCX file to storage using Aspose.Words Cloud API and converting to PDF.

string localFolder = "C:/Temp/";
string remoteFolder = "Temp";
string localName = "02_pages.docx";
string remoteName = "TestSaveAsFromDocToPdf.docx";

Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest uploadRequest = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localFolder + localName), remoteFolder + "/" + remoteName);
wordsApi.UploadFile(uploadRequest);

var pdfSecurity = new PdfEncryptionDetailsData()
{
    UserPassword = "userpassword",
    OwnerPassword = "ownerpassword"
};

var request = new SaveAsRequest(
    name: remoteName,
    saveOptionsData: new PdfSaveOptionsData()
    {
        SaveFormat = "pdf",
        FileName = "TestSaveAsFromDoctoPdf.pdf",
        EncryptionDetails = pdfSecurity

    },
    folder: remoteFolder
);

var actual = wordsApi.SaveAs(request);