2017-08-09 9 views
0

pdfドキュメントの別の部分へのリンクにPDFでプレーンテキストを作成するにはどうすればよいですか? 現在、私はPDFを後処理しています。私は2つの数字(テキストオブジェクト)がページ内にある場合、パックを互いにリンクするべき2ページを特定しました。呼び出すリンク/注釈をPDFにする他のページアクションを

このテキストをクリック可能なローカルリンクに変換する方法はありますか?

+0

自体は無関係であるテキストは、テキストの周りにボックスの座標です。 PDF後処理を行うためにどのライブラリを使用していますか? –

+0

テキストの周囲のボックスの座標は、テキスト抽出の一部としてsyncfusionが提供するものとは思われません。 –

+0

@PatrickGallotそれはsyncfusionです。潜在的に、別のlibを使用しますか? – user1093111

答えて

1

報告されたクエリ "をテキストにリンクして、PDF内の他のページアクションを呼び出すリンク/注釈を作成します。"を確認し、要件を満たすテストサンプルを用意しました。このサンプルでは、​​PdfDocumentLinkAnnotationを使用してテキストをクリックして内部文書をナビゲートしています。サンプルをチェックしてください。参照用に下記のリンクから入手できます。

the following linkからサンプルを探してください。

さらにについてはUG documentation linkをご覧ください。リンクで

コード:何が必要

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 
using System.Diagnostics; 
using System.Drawing; 
using System.Drawing.Imaging; 

using Syncfusion.Pdf; 
using Syncfusion.Pdf.Graphics; 
using Syncfusion.Pdf.Interactive; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     public static string DataPathOutput 
     { 
      get 
      { 
       if (!Directory.Exists(System.Environment.CurrentDirectory + @"\..\..\Output\")) 
        Directory.CreateDirectory(System.Environment.CurrentDirectory + @"\..\..\Output\"); 
       return System.Environment.CurrentDirectory + @"\..\..\Output\"; 
      } 
     } 

     static void Main(string[] args) 
     { 
      // Creates a new PDF document 
      PdfDocument document = new PdfDocument(); 

      // Creates a first page 
      PdfPage firstPage = document.Pages.Add(); 

      PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f); 
      PdfBrush brush = PdfBrushes.Black; 
      PdfGraphics graphics1 = firstPage.Graphics; 

      string inputText1 = "Sample Text-1"; 
      graphics1.DrawString(inputText1, font, brush, 10, 40); 

      // Measure string size to use same size for annotation 
      SizeF size1 = font.MeasureString(inputText1); 
      RectangleF rectangle1 = new RectangleF(10, 40, size1.Width, size1.Height); 

      // Creates a second page 
      PdfPage secondPage = document.Pages.Add(); 
      PdfGraphics graphics2 = secondPage.Graphics; 

      string secondPageInput = "Sample Text-2"; 
      graphics2.DrawString(secondPageInput, font, brush, 10, 40); 

      // Measure string size to use same size for annotation 
      SizeF size2 = font.MeasureString(inputText1); 
      RectangleF rectangle2 = new RectangleF(10, 40, size2.Width, size2.Height); 

      // Add annotation for firstpage to link second page of PdfDocumet 
      PdfDocumentLinkAnnotation firstAnnotation = new PdfDocumentLinkAnnotation(rectangle1); 
      firstAnnotation.Color = new PdfColor(Color.Transparent); 
      firstAnnotation.Destination = new PdfDestination(secondPage); 
      // Use below comment for link specific part of page 
      //firstAnnotation.Destination.Location = new Point(10, 40); 
      firstPage.Annotations.Add(firstAnnotation); 

      // Add annotation for second page to link first page of PdfDocumet 
      PdfDocumentLinkAnnotation secondAnnotation = new PdfDocumentLinkAnnotation(rectangle2); 
      secondAnnotation.Color = new PdfColor(Color.Transparent); 
      secondAnnotation.Destination = new PdfDestination(firstPage); 
      // Use below comment for link specific part of page 
      //secondAnnotation.Destination.Location = new Point(10, 40); 
      secondPage.Annotations.Add(secondAnnotation); 

      // Save document on mentioned location 
      document.Save(System.IO.Path.Combine(DataPathOutput, "Output.pdf")); 
      document.Close(true); 
     } 
    } 
} 
+0

うわー。おかげで多く – user1093111

+0

リンクは最終的に腐敗するでしょう、あなたの答えにそれらの内容を要約できますか? –

+0

@PaulHコードを追加しました。 – user1093111

関連する問題