We are pleased to announce the monthly release of Aspose.PDF for Java 18.6. This release includes some useful features including rotating text in PDF and converting PDF to XLSX. In order to get an idea about all new features and bug fixes incorporated in this release, please check the release notes page of Aspose.PDF for Java 18.6. In case you are planning to upgrade your existing version to the latest one, we recommend you please check the Public API Changes section in release notes of the API. This way you will have an idea about what has been changed and added new in the latest release.

The following section provides insights into major new features available in Aspose.PDF for Java 18.6.

Rotate Text in PDF using Java

Adding text with a rotation angle can be an important requirement in particular scenarios of text generation in PDF. In order to add text with rotation in PDF document, you can use the setRotation() method of TextState Class to specify the rotation angle of the text.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
// Open document
Document pdfDocument = new Document();
// Get particular page
Page pdfPage = (Page)pdfDocument.getPages().add();
// Create rotated text fragment
TextFragment tf = new TextFragment("rotated text");
tf.setPosition(new Position(200, 600));
// Set text properties
tf.getTextState().setFontSize(12);
tf.getTextState().setFont(FontRepository.findFont("TimesNewRoman"));
tf.getTextState().setBackgroundColor(com.aspose.pdf.Color.getLightGray());
tf.getTextState().setForegroundColor(com.aspose.pdf.Color.getRed());
tf.getTextState().setRotation(45);
tf.getTextState().setUnderline(true);
// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// Append the text fragment to the PDF page
textBuilder.appendText(tf);
// Save document
pdfDocument.save("TextFragmentTests_Rotated.pdf");

For more information about this new feature, please check the following article in API documentation:

Determine Rotation Angle of Text Characters

Along with the functionality of adding rotated text inside PDF, extraction of that text and determining rotation angle of text characters has also been implemented in this release of the API. TextFragmentAbsorber class has further been enhanced to support the extraction of the rotation angle of text characters.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("PdfWithRotatedText.pdf");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("R");
// Accept the absorber for first page of document
pdfDocument.getPages().get_Item(4).accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
Iterator<TextFragment> iterF = textFragmentCollection.iterator(); //assume textFragmentCollection has 2 results
while (iterF.hasNext())
{
TextFragment tf = iterF.next();
System.out.println("Fragment: " + tf.getText() + " " + tf.getRectangle());
TextFragmentState state = tf.getTextState();
System.out.println("Rotation: " + state.getRotation());
Iterator<TextSegment> iterS = tf.getSegments().iterator(); //assume textFragmentCollection has 2 results
while (iterS.hasNext())
{
TextSegment ts = iterS.next();
System.out.println("Segment: " + ts.getText() + " " + ts.getRectangle());
Iterator<CharInfo> iterC = ts.getCharacters().iterator();
while (iterC.hasNext())
{
CharInfo cI = iterC.next();
System.out.println(cI.getPosition());
}
}
}

You can check the following article in the API documentation for further details regarding this feature.

Convert PDF to XLSX in Java

PDF to XLS as well as other file format conversion was already supported in Aspose.PDF for Java. However, a new conversion feature i.e. PDF to XLSX has been introduced in this release of the API.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java
Document doc = new Document("input.pdf");
// Initialize ExcelSaveOptions
ExcelSaveOptions options = new ExcelSaveOptions();
// Set output format
options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
// Save output file
doc.save("ouput.xlsx", options);

In order to use this feature of the API, please read the following article:

Important API Changes

All descendants of com.aspose.pdf.Operator has been moved under the namespace com.aspose.pdf.operators. Thus ’new com.aspose.pdf.operators.GSave()’ should be used instead of ’new com.aspose.pdf.Operator.GSave()’. While upgrading to the latest version of the API, you will need to upgrade your existing code where you were using the previous com.aspose.pdf.Operator namespace.

Miscellaneous Fixes

Along with the features and enhancements mentioned above, followings are useful improvements and bug fixes included in the latest release of API:

  • PDF to HTML Conversion has been improved in terms of visibility and formatting of symbols
  • Fonts handling and watermark rendering have been improved further
  • Improved memory consumption by API methods and calls
  • Worked over formula based fields while converting from XFA to Standard AcroForms
  • Consistency of text format has been maintained while converting PDF to PDF/A
  • Redaction Annotation feature has been further improved
  • Worked over producing better results while extracting bookmarks from PDF

As it is always recommended to use the latest release of our API’s because they include the latest features/improvements and fixes related to issues reported in earlier released versions. Therefore, please download the latest release of Aspose.PDF for Java 18.6.