Aspose.Total for Java is a comprehensive suite of APIs that enables developers to integrate PDF to TXT conversion feature in their Java applications. It consists of two APIs, Aspose.PDF for Java and Aspose.Cells for Java, which can be used in a two-step process to convert PDF to TXT.
The first step involves using Aspose.PDF for Java to render PDF to XLSX. Aspose.PDF for Java is a powerful PDF manipulation API that enables developers to create, edit, convert, and manipulate PDF documents without any external dependencies. It provides a wide range of features such as PDF to image conversion, text extraction, form filling, document signing, and more.
In the second step, Aspose.Cells for Java can be used to convert XLSX to TXT. Aspose.Cells for Java is a Spreadsheet Programming API that enables developers to create, manipulate, and convert spreadsheets in various formats such as XLSX, XLS, CSV, and ODS. It provides a wide range of features such as data validation, formula calculation, chart creation, and more.
By using Aspose.Total for Java, developers can easily integrate PDF to TXT conversion feature in their Java applications. It is a reliable and cost-effective solution that can be used to create, edit, and convert PDF documents with ease. Furthermore, it is a secure and reliable solution that ensures the safety of your data.
Convert PDF File to TXT via Java
Conversion Requirements
You can easily use Aspose.Total for Java directly from a Maven based project and include Aspose.PDF for Java and Aspose.Cells for Java in your pom.xml.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF with an instance of Document | |
Document document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |
Convert Protected PDF to TXT via Java
If your PDF document is password protected, you cannot convert it to TXT without the password. Using the API, you can first open the protected document using a valid password and convert it after it. In order to open the encrypted file, you can initialize a new instance of the Document class and pass filename and password as arguments.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// open PDF document | |
Document doc = new Document("input.pdf", "Your@Password"); | |
// save PDF as XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |
Convert PDF File to TXT with Watermark via Java
While converting PDF file to TXT, you can also add watermark to your output TXT file format. In order to add a watermark, create a new Workbook to open the converted XLSX file. Select Worksheet via its index, create a Shape and use its addTextEffect function, set colors, transparency and more. After that you can save your XLSX document as TXT with Watermark.
// supports PDF, CGM, EPUB, TeX, PCL, PS, SVG, XPS, MD, MHTML, XML, and XSLFO file format | |
// load PDF with an instance of Document | |
Document document = new Document("template.pdf"); | |
// save document in XLSX format | |
document.save("XlsxOutput.xlsx", SaveFormat.Xlsx); | |
// load the XLSX file in an instance of Workbook | |
Workbook book = new Workbook("XlsxOutput.xlsx"); | |
// get the first default sheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// add Watermark | |
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL", | |
"Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800); | |
// get the fill format of the word art | |
FillFormat wordArtFormat = wordart.getFill(); | |
// set the color | |
wordArtFormat.setOneColorGradient(Color.getRed(), 0.2, GradientStyleType.HORIZONTAL, 2); | |
// set the transparency | |
wordArtFormat.setTransparency(0.9); | |
// make the line invisible | |
LineFormat lineFormat = wordart.getLine(); | |
lineFormat.setWeight(0.0); | |
// supports CSV, XLSB, XLSM, XLT, XLTX, XLTM, XLAM, TSV, TXT, ODS, DIF, MD, SXC, and FODS file format | |
// save XLSX as CSV | |
book.save("output.csv", SaveFormat.AUTO); |