2009-04-23 30 views

回答

1

您可以使用像this one這樣的庫來打開和修改PDF文件並將每個超鏈接對象轉換爲簡單文本。

1

Docotic.Pdf我參與的庫可用於查找PDF中的超鏈接並將其刪除。

下面是示例代碼,正是這一點:

public static void RemoveHyperlinks(string inputFile, string outputFile) 
{ 
    using (PdfDocument doc = new PdfDocument(inputFile)) 
    { 
     foreach (PdfPage page in doc.Pages) 
     { 
      for (int i = 0; i < page.Widgets.Count; i++) 
      { 
       PdfWidget widget = page.Widgets[i]; 
       PdfActionArea actionArea = widget as PdfActionArea; 
       if (actionArea != null) 
       { 
        PdfUriAction linkAction = actionArea.Action as PdfUriAction; 
        if (linkAction != null) 
        { 
         page.Widgets.RemoveAt(i); 
         i--; 
        } 
       } 
      } 
     } 

     doc.Save(outputFile); 
     System.Diagnostics.Process.Start(outputFile); 
    } 
} 

請注意,有些觀衆可以檢測來自文本超鏈接,並仍然提供它們可點擊區域,即使沒有在PDF本身定義的鏈接。例如,具有特定設置的Adobe Reader可以做到這一點。

P.S.我知道這個問題很老,但也許我的回答會讓新訪客受益。

相關問題