Free Support Forum - aspose.cloud

Convert DOCX to PDF in JAVA with Aspose.Words Cloud API error

Hi,


I am trying a simple example to load and convert a word .docx file to pdf,

try {
// Instantiate Aspose Storage API SDK
StorageApi storageApi = new StorageApi(apiKey, appSID, true);

// Instantiate Aspose Words API SDK
WordsApi wordsApi = new WordsApi(apiKey, appSID, true);

// set input file name

String format = “pdf”;
String outPath = “”;
File file;

file = new File(“d:\tmp\invoice.docx”);
ResponseMessage result = wordsApi.PutConvertDocument(format,
outPath, file);

} catch (ApiException apiException) {
System.out.println(“apiExp:” + apiException.getMessage());
}

I am getting on output:

Mar 11, 2016 11:31:37 AM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 500
1 < X-AspNet-Version: 4.0.30319
1 < Date: Fri, 11 Mar 2016 11:31:32 GMT
1 < Content-Length: 36
1 < Expires: -1
1 < Connection: keep-alive
1 < Content-Type: application/json; charset=utf-8
1 < X-Powered-By: ASP.NET
1 < Server: Microsoft-IIS/8.0
1 < Pragma: no-cache
1 < Cache-Control: no-cache
1 <
{“Message”:“An error has occurred.”}

Can you possibly help me out with what the issue may be?

Many Thanks,
Barry.
  • problem was that the file needed stored first - I wasn’t doing that.

Hi Barry,


It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,

@barrychoc

Please note in the latest API Version V4.0 ConvertDocument converts documents from the request body instead of cloud storage. Please find updated sample .NET code for DOCX to PDF conversion.

// Get Client Secret and Client Id from https://dashboard.aspose.cloud/
WordsApi wordsApi = new WordsApi(MyClientSecret, MyClientId);

var request = new ConvertDocumentRequest(
    document: File.OpenRead("C:/Temp/Test File.docx"),
    format: "pdf"
);

var result = wordsApi.ConvertDocument(request);
var fileStream = System.IO.File.Create("C:/Temp/Test.pdf");
result.CopyTo(fileStream);
fileStream.Close();