/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:セキュリティ解除 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace Decrypt { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: Decrypt.exe in-pdf-file out-pdf-file in-pdf-password"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) using (PtlParamOutput outputFile = new PtlParamOutput(args[1])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // パスワードのセット doc.setPassword(args[2]); // PDFファイルをロードします。 doc.load(inputFile); // 暗号化の取得 if (doc.isEncrypted()) { if (doc.hasOwnerAuthority()) { // 暗号化の削除 doc.removeEncrypt(); } else { Console.WriteLine("パスワードに処理権限がありません"); return; } } else { Console.WriteLine("暗号化されていないファイルです"); return; } // ファイルに保存します。 doc.save(outputFile); } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } } }