/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:ページ抽出 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace ExtractPage { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: ExtractPage.exe input-pdf out-folder"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(inputFile); // 文書プロパティの取得 using (PtlDocProperty docproperty = doc.getDocProperty()) { // 文書情報の取得 PtlDocInfo docinfo = docproperty.getDocInfo(); for (int i = 0; i < doc.getPageCount(); i++) { // 出力ファイル名 string outputfile = (string)args[1] + @"\output_" + i + @".pdf"; using (PtlPDFDocument doc_ext = new PtlPDFDocument()) using (PtlPages pages = doc_ext.getPages()) using (PtlParamOutput output = new PtlParamOutput(outputfile)) using (PtlDocProperty docproperty_ext = doc_ext.getDocProperty()) using (PtlDocInfo docinfo_ext = docproperty_ext.getDocInfo()) { // タイトルをコピー docinfo_ext.setTitle(docinfo.getTitle()); // 著者をコピー docinfo_ext.setAuthor(docinfo.getAuthor()); // サブジェクトをコピー docinfo_ext.setSubject(docinfo.getSubject()); // キーワードをコピー docinfo_ext.setKeywords(docinfo.getKeywords()); // クリエータをコピー docinfo_ext.setCreator(docinfo.getCreator()); // プロデューサをコピー docinfo_ext.setProducer(docinfo.getProducer()); // 作成日付をコピー docinfo_ext.setCreationDate(docinfo.getCreationDate()); // 更新日付をコピー docinfo_ext.setModDate(docinfo.getModDate()); // ページ挿入オプション //OPTION_COPY_OUTLINES = 0x00000004 ページ挿入時にあわせてしおりをコピーします。 //OPTION_COPY_ATTACHEDFILES = 0x00000008ページ挿入時にあわせて添付ファイルをコピーします。 PtlPages.INSERT_OPTION insertoption = (PtlPages.INSERT_OPTION.OPTION_COPY_OUTLINES | PtlPages.INSERT_OPTION.OPTION_COPY_ATTACHEDFILES); // ページの追加(iページから1P) pages.append(doc, i, 1, insertoption); // ファイルに保存します。 doc_ext.save(output); } } } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } } }