Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active June 25, 2022 23:13
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/c9a62ceeeb670b71c27d75c9383f057f to your computer and use it in GitHub Desktop.
Save blog-aspose-cloud/c9a62ceeeb670b71c27d75c9383f057f to your computer and use it in GitHub Desktop.
Convert PDF to Text in Java

Convert PDF to Text in Java


This Gist provides the details on how to convert PDF to TXT using Aspose.Words Cloud SDK for Java.
In one of the scenarios, we are going to accomplish our requirement, by first reading the PDF file from local drive using File instance, then uploading it to Cloud storage using uploadFile(...)method of WordsApi, and perform the conversion using getDocumentWithFormat(...) method. After successful conversion, the resultant file is saved in cloud storage. For complete information, please visit Convert PDF to TXT in Java.

Convert PDF to TXT

Important Links

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

Convert PDF to Text in Java
// 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 PDF from local drive
File file = new File("c://input.pdf");
// create file upload request
UploadFileRequest uploadRequest = new UploadFileRequest(Files.readAllBytes(file.toPath()), "input.pdf", null);
// upload file to cloud storage
wordsApi.uploadFile(uploadRequest);
// create document conversion request object
GetDocumentWithFormatRequest request = new GetDocumentWithFormatRequest("input.pdf", "PDF", "", "Internal","", "", "", "extracted.txt","");
// Call API to convert PDF to Text online
wordsApi.getDocumentWithFormat(request);
System.out.println("PDF to TXT Conversion sucessfull !");
}catch(Exception ex)
{
System.out.println(ex);
}
// 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 PDF from local drive
File file = new File("c://input.pdf");
// create document conversion request object
ConvertDocumentRequest request = new ConvertDocumentRequest(Files.readAllBytes(file.toPath()), "TXT", "Extracted.txt", null, null, null);
// Call API to convert PDF to Text format
wordsApi.convertDocument(request);
System.out.println("PDF to TXT 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