- 取得連結
- 以電子郵件傳送
- 其他應用程式
iTextSharp 可以將 PDF 檔案設定為保護中的檔案,僅能進行唯讀。
文章環境
- iTextSharp
- 5.5.9
- Windows 主控台應用程式
- NET Framework 4.6
流程說明
使用 PdfStamper 類別的方法 SetEncryption 指定 Permissions 為 AllowScreenReaders 後將處理完成的檔案進行輸出。
使用 Adobe Reader 開啟 PDF 檔案後會出現(已保護)文字訊息。
程式碼片段說明
範例程式碼中取得 PDF 檔案的位元陣列,設定為唯讀後透過位元陣列進行回傳。
應用程式截圖
使用 Adobe Reader 開啟 PDF 檔案。
![原始 PDF 檔案內容](https://raw.githubusercontent.com/txstudio/blogspot-image/master/itextsharp/secured-pdf/01-orginal-pdf-file.gif)
PDF 檔案的文件內容。
![原始 PDF 檔案文件內容](https://raw.githubusercontent.com/txstudio/blogspot-image/master/itextsharp/secured-pdf/02-orginal-pdf-file-property.gif)
使用 Adobe Reader 開啟受保護的 PDF 檔案。
![檔案為受保護應用程式標題](https://raw.githubusercontent.com/txstudio/blogspot-image/master/itextsharp/secured-pdf/03-secured-pdf-file.gif)
PDF 檔案的文件內容。
![受保護檔案的文件內容](https://raw.githubusercontent.com/txstudio/blogspot-image/master/itextsharp/secured-pdf/04-secured-pdf-file-property.gif)
範例程式碼
範例程式碼可以在下列連結取得
txstudio.iTextSharp.SampleCode.Secured
留言
張貼留言