Convert Word to PDF with Java SDK of Aspose.Words Cloud throws forbidden error

I am trying to convert a word document to a pdf using the cloud api. I have a storage mapped to amazon s3. My Java code is as follows:

String amazonS3StorageName = “MyStorageName”;

//build URI to convert MS Word file to other format using storage

String strURI = “http://api.aspose.cloud/v1.1/words/” + fileName + “?format=pdf&storage=” + amazonS3StorageName + “&folder=” + bucket + “/” + folderPath;

//sign URI

System.out.println(strURI);

String signedURI = Sign(strURI, appSID, appKey);

System.out.println(signedURI);

try

{

InputStream responseStream = ProcessCommand(signedURI, “GET”);

//boolean response = SaveStreamToFile(relativePath + “.pdf”, responseStream);

responseStream.close();

}

catch(Exception e)

{

}

The problem is, I am always getting “Forbidden”.

I don’t see what the problem with this is. I just modified an example I found on your website.

Hi Ash,

Can you please confirm if you have followed these steps https://docs.aspose.cloud/display/totalcloud/Configure+Amazon+S3+Storage to map your S3 storage with Aspose Cloud? If yes, can you please send following information to me at muhammad.ijaz@aspose.com?

  • Your App SID and App Key
  • Name of the mapped storage
  • Your S3 bucket name

Best Regards,

@ash2

You can also convert the Word document PDF without using the cloud storage using ConvertDocument API method. Please check the sample Java code for reference.

// Get Client ID and Client Secret from https://dashboard.aspose.cloud/
WordsApi wordsApi = new WordsApi("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx","xxxxxxxxxxxxxxxxxxxxxxxxxxxx","https://api.aspose.cloud");


try {
	
	ConvertDocumentRequest request = new ConvertDocumentRequest(
            Files.readAllBytes(Paths.get("C:/Temp/02_pages.docx").toAbsolutePath()),
            "pdf",
            null,
            null,
            null,
            null
        );

        File result = wordsApi.convertDocument(request);
        System.out.println("api request completed...");
        File dest = new File("C:/Temp/02_pages_java.pdf");
		Files.copy(result.toPath(), dest.toPath(),
		java.nio.file.StandardCopyOption.REPLACE_EXISTING);
			
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}