/* Antenna House PDF Tool API V7.0 .NET Interface sample program 概要:しおりの追加 Copyright 2013-2021 Antenna House, Inc. */ using System; using PdfTkNet; namespace AppendOutline { class Program { static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("usage: AppendOutline.exe in-pdf-file out-pdf-file"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) using (PtlParamOutput outputFile = new PtlParamOutput(args[1])) using (PtlPDFDocument doc = new PtlPDFDocument()) { // PDFファイルをロードします。 doc.load(inputFile); // ルートアウトラインの取得 using (PtlOutline outlineRoot = doc.getRootOutline()) { // しおりの追加 createOutline(outlineRoot); } // ファイルに保存します。 doc.save(outputFile); } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("-- 完了 --"); } } static void createOutline(PtlOutline outlineRoot) { // GoToアクション ------------------------------- using (PtlOutline outlineActionGoTo = new PtlOutline()) { outlineActionGoTo.setTitle("ActionGoTo DestFit"); // PtlActionGoTo : GoToアクション<現在のドキュメント内の宛先へ移動> using (PtlActionGoTo actiongoto = new PtlActionGoTo()) // PtlDestFit : Fit型
using (PtlDestFit destfit = new PtlDestFit()) { // 宛先ページの設定 destfit.setPageNumber(1); // 宛先の設定 actiongoto.setDest(destfit); // アクションの設定 outlineActionGoTo.setAction(actiongoto); } // アウトラインタイトルの色を設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(0.0f, 1.0f, 0.0f)) { outlineActionGoTo.setColor(color); } // アウトラインフラグを設定 outlineActionGoTo.setFlags(PtlOutline.ITEM_FLAG.FLAG_ITALIC); // PDF表示時の子アウトラインをオープンするかどうかの設定 outlineActionGoTo.setOpen(true); // 子アウトラインの追加 outlineRoot.appendLastChild(outlineActionGoTo); //GoToRアクション ------------------------------- using (PtlOutline outlineActionGoToR = new PtlOutline()) { outlineActionGoToR.setTitle("ActionGoToR DestFitH"); // PtlActionGoToR : GoToRアクション<("Go-to remote")他のドキュメント内への移> using (PtlActionGoToR actiongotor = new PtlActionGoToR()) // PtlDestFitH : FitH型
using (PtlDestFitH destfith = new PtlDestFitH()) { // 宛先ページの設定 destfith.setPageNumber(1); // topの設定 destfith.setTopNull(); //dest1.setTop(NULL_VALUE_CSTR); // 宛先の設定 actiongotor.setDest(destfith); // ファイル間移動用PDFファイル名を取得(ファイル名もしくは相対パス指定) actiongotor.setFileName("test.pdf"); // 宛先文書を新ウィンドウでオープンするかどうかのフラグを設定(true: 新ウィンドウでオープンする。false: しない) actiongotor.setNewWindowFlag(false); // アクションの設定 outlineActionGoToR.setAction(actiongotor); } // アウトラインタイトルの色を設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(0.0f, 0.0f, 1.0f)) { outlineActionGoToR.setColor(color); } // アウトラインフラグを設定 outlineActionGoToR.setFlags(PtlOutline.ITEM_FLAG.FLAG_NORMAL); // PDF表示時の子アウトラインをオープンするかどうかの設定 outlineActionGoToR.setOpen(false); // 子アウトラインの追加 outlineActionGoTo.appendLastChild(outlineActionGoToR); } } // Launchアクション ------------------------------- using (PtlOutline outlineActionLaunch = new PtlOutline()) { outlineActionLaunch.setTitle("ActionLaunch"); // PtlActionLaunch : Launchアクション<アプリケーションの起動、通常、ファイルを開く> using (PtlActionLaunch actionlaunch = new PtlActionLaunch()) { // 起動ファイル名を設定 actionlaunch.setFileName("test.jpg"); // 宛先文書を新ウィンドウでオープンするかどうかのフラグを設定(true: 新ウィンドウでオープンする false: しない) actionlaunch.setNewWindowFlag(true); // アクションの設定 outlineActionLaunch.setAction(actionlaunch); } // アウトラインタイトルの色を設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(0.0f, 1.0f, 1.0f)) { outlineActionLaunch.setColor(color); } // アウトラインフラグを設定 outlineActionLaunch.setFlags(PtlOutline.ITEM_FLAG.FLAG_BOLD); // PDF表示時の子アウトラインをオープンするかどうかの設定 outlineActionLaunch.setOpen(false); // 子アウトラインの追加 outlineRoot.appendLastChild(outlineActionLaunch); } // URIアクション ----------------------------------- using (PtlOutline outlineActionURI = new PtlOutline()) { // アウトラインタイトル文字列を設定 outlineActionURI.setTitle("ActionURI"); // PtlActionURI : URIアクション using (PtlActionURI actionuri = new PtlActionURI()) { // URIを設定 actionuri.setURI("http://www.antenna.co.jp/"); // アクションの設定 outlineActionURI.setAction(actionuri); } // アウトラインタイトルの色を設定 using (PtlColorDeviceRGB color = new PtlColorDeviceRGB(.01f, 0.5f, 0.0f)) { outlineActionURI.setColor(color); } // アウトラインフラグを設定 outlineActionURI.setFlags(PtlOutline.ITEM_FLAG.FLAG_BOLD | PtlOutline.ITEM_FLAG.FLAG_ITALIC); // PDF表示時の子アウトラインをオープンするかどうかの設定 outlineActionURI.setOpen(true); // 子アウトラインの追加 outlineRoot.appendLastChild(outlineActionURI); } } } }