Create Named Destination and Get Rotation Angle of Text in existing PDF

Share on FacebookTweet about this on TwitterShare on LinkedIn

As per regular monthly release process, we are pleased to announce Aspose.PDF for .NET 18.2. The new version of Aspose.PDF for .NET has been released for .NET platform and is available now to be used in .NET applications. Since we have been providing an efficient and full of attractive features API to deal with PDF documents, we have introduced new exciting features in Aspose.PDF for .NET 18.2. In case you are going to use new version of Aspose.PDF for .NET, we suggest you to go through detailed release notes page of the API. Each new feature and enhancement has been enlisted in release notes along with the fixes, which have been made against the bugs reported in previous version(s) of the API.

Create Named Destination in existing PDF Documents

One of the exciting features introduced in Aspose.PDF for .NET 18.2 is to create names destinations in existing PDF documents. If you want to change a destination without effecting any internal/external link inside PDF document, you have to use named destination. Creating named destinations manually can be a very tedious task – however, you can also create named destinations programmatically using Aspose.PDF for .NET 18.2. We have implemented Document.NamedDestinations property which allows to manipulate named destinations. NamedDestinationCollection has the following properties:

  • IAppointment this[string name]= Access to named destination; (getter and setter are implemented)
  • int Count = Number if named destinations;
  • string[] names = List of destination names;
  • Add(string name, IAppointment appointment = Create new named destination;
  • Remove(string name) = Remove named destination by its name.

Following example shows the usage of NamedDestinations:

Document pdf = new Document();
// Create document with 100 pages
for (int i = 1; i <= 100; i++)
 Page page = pdf.Pages.Add();
 page.AddStamp(new Aspose.Pdf.TextStamp("Page " + i));
   // Named destinations for every page
 pdf.NamedDestinations.Add("Page" + i, new XYZExplicitDestination(i, 0, 600, 0.5));
for (int i = 1; i <= 100; i++)
   // Create outlines (two outlines for every page)
 OutlineItemCollection item1 = new OutlineItemCollection(pdf.Outlines);
 item1.Destination = new NamedDestination(pdf, "Page" + i);
 item1.Title = "Page  " + i + "(1)";

 OutlineItemCollection item2 = new OutlineItemCollection(pdf.Outlines);
 item2.Destination = new NamedDestination(pdf, "Page" + i);
 item2.Title = "Page  " + i + "(2)";
 // Let's update on of the named destinations
pdf.NamedDestinations["Page50"] = new XYZExplicitDestination(50, 0, 100, 2);

Get Rotation Angle of Text

In Aspose.PDF for .NET 17.5 version, we had introduced the feature of rotating the added text inside PDF document. However, we have been receiving feature requests from our customers, about determining the rotation angle of the text found using TextFragmentAbsorber class. The functionality to get rotation angle of the text has been implemented in Aspose.PDF for .NET 18.2 and can be achieved by using following code snippet:

Document pdfDocument = new Document(myDir + "input.pdf");
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("R");
// Accept the absorber for first page of document

TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment tf in textFragmentCollection)
 Console.Out.WriteLine("Fragment: " + tf.Text + " " + tf.Rectangle);

 TextFragmentState state = tf.TextState;
 Console.Out.WriteLine("Rotation: " + state.Rotation);

 foreach (TextSegment ts in tf.Segments)
  Console.Out.WriteLine("Segment: " + ts.Text + " " + ts.Rectangle);

  foreach (CharInfo cI in ts.Characters)

Miscellaneous Fixes

Besides the above mentioned enhancements and features, we also have provided fixes against bugs reported in previous version(s) of the Aspose.PDF for .NET. In order to check the complete list of issues which have been fixed in this release of Aspose.Pdf for .NET, please check Release Notes section of Aspose.Pdf for .NET 18.2.

As it is always recommended to use latest release of our API’s, so we suggest you to please download the latest release Aspose.PDF for .NET 18.2 and check following resources which will help you working with API: