Tilal Ahmad Sana November 2, 20160 Comments

Wrap Lines Implementation and Calculate Text Index in TextFragment with Aspose.Pdf for Java 16.10.0

Wrap Lines Implementation and Calculate Text Index in TextFragment with Aspose.Pdf for Java 16.10.0

November 2, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce Aspose.Pdf for Java 16.10.0 release. This version of Aspose.Pdf for Java includes same features and enhancements introduced in Aspose.Pdf for .NET 16.10.0 along with number of fixes of the bugs reported in older versions of Aspose.Pdf for Java. These enhancements and imporvements add further value to API stability and prove it more reliable API for PDF document processing. Some of the new features of this release are support of Warp Lines, None Line style of TOC element and calculation of text index in TextFragment. Please check the detailed release notes to get an idea about the issues fixed in this revision of Aspose.Pdf for Java.

Please note if you are planning to upgrade the API from any previous version, we strongly suggest you to check the Public API Changes section of current release and other intermediate releases, to know what has been changed since your current revision of the API.

The following sections describe some details regarding these newly added enhancements.

Set TOC Line Style to None

Some customers have business requirement to create TOC elements without any line style. So we have introduced a new LiesDash property in TocInfo class to set TOC dash line style to none in Aspose.Pdf for .NET 16.10.0. Please check following code snippet to set LineDash value to None from TabLeaderType enum:


//Create object to represent TOC information

TocInfo tocInfo = new TocInfo();

TextFragment title = new TextFragment("Table Of Contents");



//Set the title for TOC


//Set TOC line dash style



Support of Wrap line in New Generator

We have introduced Wrap line feature in TextFragment class of new generator. We can use this feature in all the Objects those support Paragraph object e.g. Page, Table object. We can accomplish this task by setting desired value of setWrapLinesCount property of TextFragment object as following:

//Load source PDF document

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

// Add page

Page page = doc.getPages().add();

// Initializes a new instance of the Table

com.aspose.pdf.Table table = new com.aspose.pdf.Table();

// Set the table border color as LightGray

table.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, .5f, com.aspose.pdf.Color.getLightGray()));

// Set the border for table cells

table.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, .5f, com.aspose.pdf.Color.getLightGray()));

// Create a loop to add 10 rows

for (int row_count = 1; row_count < 10; row_count++)


// Add row to table

com.aspose.pdf.Row row = table.getRows().add();

// Add table cells

TextFragment fragment = new TextFragment("Very long text in column ("+row_count+ ", 1)");


Cell cell = new Cell();



row.getCells().add("Column ("+row_count+", 2)");

row.getCells().add("Column ("+row_count+", 3)");


// Add table object to first page of input document



Calculation of Text index in TextFragment

One of the customer has requirement to calculate text index in TextFragment. Please note PDF document does not contain any definition of “line”. PDF operates with text segments (text show operators) those are absolutely positioned on the page anywhere. Mostly PDF text segment represents one line in the text. But sometimes it may represents a part of the line. Therefore often index of fragment in physical text segment will be also index in the line.

We have added two read-only properties StartCharIndex and EndCharIndex in TextSegment Class. These properties get starting / ending character index of current segment in the show text operator (Tj, TJ) segment. Please consider the following code to get text Index in TextFragment.

TextFragmentAbsorber absorber = new TextFragmentAbsorber("Windows");

Document doc = new Document("SimpleInput.pdf");


for (TextFragment textFragment : (Iterable<TextFragment>) absorber.getTextFragments())


int position = textFragment.getSegments().get_Item(1).getStartCharIndex();

System.out.println("Starting position of "+textFragment.getText()+ " word is "+position+ " in the text show operator.");


Miscellaneous fixes

We have improved PDF to PDFA conversion feature in this release with fixing number of related issues. This version also includes some other important bug fixes along with above stated enhancements. Please check release notes of Aspose.Pdf for Java 16.10.0 for complete list of bug fixed.

Aspose.Pdf for Java Resources

The following resources will help you work with Aspose.Pdf for Java:

Leave a comment

Posted inAspose.PDF Product Family

Related Articles