Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active June 25, 2022 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blog-aspose-cloud/b55575407d39a83c114400cd791f2e3e to your computer and use it in GitHub Desktop.
Save blog-aspose-cloud/b55575407d39a83c114400cd791f2e3e to your computer and use it in GitHub Desktop.
Convert TXT to PDF Online

Convert TXT to PDF Online


This Gist provides the details on how to convert TXT to PDF usingAspose.Words Cloud SDK for Java.
In order to accomplish this requirement, we need to read the content of Text file from local drive using File instance, upload it to Cloud storage using uploadFile(...)method of WordsApi, create an object of GetDocumentWithFormatRequest where we specify PDF as output format and finally, call the method getDocumentWithFormat(...)to perform the conversion and save the resultant PDF in cloud storage. For complete information, please visit Convert TXT to PDF using Java.

Convert TXT to PDF

Important Links

Product Page | Docs | Live Demo | Swagger UI | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

Online TXT to PDF Conversion using Java SDK
// for more examples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/
String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";
// create an object of WordsApi
// if baseUrl is null, WordsApi uses default https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
// read the content of TXT file from local drive
File file = new File("c://CAD-Errors.txt");
// create file upload request
UploadFileRequest uploadRequest = new UploadFileRequest(Files.readAllBytes(file.toPath()), "input.txt", null);
// upload file to cloud storage
wordsApi.uploadFile(uploadRequest);
// create document conversion request object
GetDocumentWithFormatRequest request = new GetDocumentWithFormatRequest("input.txt", "PDF", "", "Internal","", "", "", "resultant.pdf","");
// Call API to convert TXT to PDF format
wordsApi.getDocumentWithFormat(request);
System.out.println("TXT to PDF Conversion sucessfull !");
}catch(Exception ex)
{
System.out.println(ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment