Create Named Destination and Get Rotation Angle of Text in PDF using C#

As per the 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 the new version of Aspose.PDF for .NET, we suggest you go through the 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 the previous version(s) of the API.

Create Named Destination in PDF using C#

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 a PDF document, you have to use the 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 the Document.NamedDestinations property which allows manipulating 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)";
 pdf.Outlines.Add(item1);

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

Get Rotation Angle of Text in PDF

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 the following code snippet:

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

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)
  {
   Console.Out.WriteLine(cI.Position);
  }
 }
}

Miscellaneous Fixes

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

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