在现有PDF中创建已命名目标并获取文本的旋转角度

按照每月定期发布流程,我们十分高兴的宣布Aspose.PDF for .NET 18.2新版本的发布。新版本的Aspose.PDF for .NET适用于.NET平台,现在已可用于.NET应用程序。 由于我们一直提供高效且充满吸引力的功能API来处理PDF文档,因此我们在Aspose.PDF for .NET 18.2中引入了新的令人兴奋的功能。如果您打算使用新版本的Aspose.PDF for .NET,我们建议您阅读API的详细发行说明页面。每个新增功能和增强功能都已添加到发布说明中,并且针对API以前版本中报告的错误进行了修复。

在现有的PDF文档中创建已命名目标

Aspose.PDF for .NET 18.2中引入的令人兴奋的功能之一是在现有PDF文档中创建已命名目标。如果您想在不影响PDF文档内部的任何内部/外部链接的情况下更改目标,则必须使用已命名目标。手动创建已命名目标可能是一项非常繁琐的任务 – 但是,您也可以使用Aspose.PDF for .NET 18.2以编程方式创建已命名目标。我们已经实现了利用Document.NamedDestinations属性来操作已命名目标。 NamedDestinationCollection具有以下属性:

  • 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.

以下示例显示了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");

获取文本的旋转角度

在Aspose.PDF for .NET 17.5版本中,我们引入了在PDF文档中旋转已添加文本的功能。但是,我们一直在接收来自客户的功能请求,关于确定使用TextFragmentAbsorber类来找到文本的旋转角度。获取文本旋转角度的功能已经在Aspose.PDF for .NET 18.2中实现,可以通过使用以下代码片段来实现:

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);
  }
 }
}

其它修复

除了上述增强功能和特性之外,我们还针对以前版本Aspose.PDF for .NET中报告的错误进行了修复。为了查阅在此版本Aspose.Pdf for .NET中修复的问题的完整列表,请检查Aspose.Pdf for .NET 18.2的发行说明部分。

我们始终推荐使用API的最新版本,所以我们建议您下载最新版本的Aspose.PDF for .NET 18.2并查阅以下资源,这些资源可以帮助你使用API: