/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:文書情報の取得(バージョン・文書情報・PDFの開き方・セキュリティ情報) Copyright 2013-2026 Antenna House, Inc. */ using PdfTkNet; namespace GetDocInfo_2 { class Program { static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage: GetDocInfo_2.exe in-pdf-file"); return; } try { using (PtlParamInput inputFile = new PtlParamInput(args[0])) using (PtlPDFDocument doc = new PtlPDFDocument()) { //PDFファイルをロードします。 doc.load(inputFile); //PDFの文書プロパティ using (PtlDocProperty docproperty = doc.getDocProperty()) { Console.WriteLine("PDF Version"); switch (docproperty.getVersion()) { case PtlDocProperty.PDF_VERSION.PDFV1_0: // PDF-1.0 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 0"); break; case PtlDocProperty.PDF_VERSION.PDFV1_1: // PDF-1.1 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 1"); break; case PtlDocProperty.PDF_VERSION.PDFV1_2: // PDF-1.2 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 2"); break; case PtlDocProperty.PDF_VERSION.PDFV1_3: // PDF-1.3 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 3"); break; case PtlDocProperty.PDF_VERSION.PDFV1_4: // PDF-1.4 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 4"); break; case PtlDocProperty.PDF_VERSION.PDFV1_5: // PDF-1.5 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 5"); break; case PtlDocProperty.PDF_VERSION.PDFV1_6: // PDF-1.6 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 6"); break; case PtlDocProperty.PDF_VERSION.PDFV1_7: // PDF-1.7 Console.WriteLine(" major : 1"); Console.WriteLine(" minor : 7"); break; case PtlDocProperty.PDF_VERSION.PDFV2_0: // PDF-2.0 Console.WriteLine(" major : 2"); Console.WriteLine(" minor : 0"); break; case PtlDocProperty.PDF_VERSION.PDFV_UNSUPPORTED: // 未サポートのバージョン Console.WriteLine(" 未サポートのバージョン"); break; } //PDFの文書情報 Console.Write(Environment.NewLine); Console.WriteLine("Document Information"); using (PtlDocInfo docinf = docproperty.getDocInfo()) { //タイトル取得 Console.WriteLine(" Title : " + docinf.getTitle()); //サブジェクト取得 Console.WriteLine(" Subject : " + docinf.getSubject()); //著者取得 Console.WriteLine(" Author : " + docinf.getAuthor()); //キーワード取得 Console.WriteLine(" Keywords : " + docinf.getKeywords()); //クリエータ取得 Console.WriteLine(" Creator : " + docinf.getCreator()); //プロデューサ取得 Console.WriteLine(" Producer : " + docinf.getProducer()); //作成日付を取得 using (PtlDate date = docinf.getCreationDate()) { int year = date.getYear(); int month = date.getMonth(); int day = date.getDay(); int hour = date.getHour(); int min = date.getMin(); int sec = date.getSec(); Console.WriteLine(" CreationDate : {0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, min, sec); } //更新日付を取得 using (PtlDate date = docinf.getModDate()) { int year = date.getYear(); int month = date.getMonth(); int day = date.getDay(); int hour = date.getHour(); int min = date.getMin(); int sec = date.getSec(); Console.WriteLine(" ModifyDate : {0}/{1}/{2} {3}:{4}:{5}", year, month, day, hour, min, sec); } } // ページ数 Console.WriteLine(" Max Page : {0}", doc.getPageCount()); // 開き方情報を取得 Console.WriteLine(Environment.NewLine); Console.WriteLine("View Information"); PtlOpenMode openmode = docproperty.getOpenMode(); //読み上げオプション取得 switch (docproperty.getDirection()) { case PtlDocProperty.DIRECTION.DIRECTION_L2R: Console.WriteLine(" Direction : Left to Right"); break; case PtlDocProperty.DIRECTION.DIRECTION_R2L: Console.WriteLine(" Direction : Right to Left )"); break; } // ページレイアウトを取得 switch (openmode.getPageLayout()) { case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_SINGLE_PAGE: // 単一ページ Console.WriteLine(" PageLayout : SinglePage"); break; case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_ONE_COLUMN: // 連続ページ Console.WriteLine(" PageLayout : OneColumn"); break; case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_TWO_COLUMN_LEFT: // 奇数ページを左側にして連続見開きページ Console.WriteLine(" PageLayout : TwoColumnLeft"); break; case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_TWO_COLUMN_RIGHT: // 奇数ページを右側にして連続見開きページ Console.WriteLine(" PageLayout : TwoColumnRight"); break; case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_TWO_PAGE_LEFT: // 奇数ページを左側にして見開きページ Console.WriteLine(" PageLayout : TwoPageLeft"); break; case PtlOpenMode.PAGE_LAYOUT.PAGE_LAYOUT_TWO_PAGE_RIGHT: // 奇数ページを右側にして見開きページ Console.WriteLine(" PageLayout : TwoPageRight"); break; } // PageMode : Use Outlines switch (openmode.getPageMode()) { case PtlOpenMode.PAGE_MODE.PAGE_MODE_USE_NONE: // ページのみ表示 Console.WriteLine(" PageMode : Use None"); break; case PtlOpenMode.PAGE_MODE.PAGE_MODE_USE_OUTLINES: // アウトラインパネルとページ Console.WriteLine(" PageMode : Use Outlines"); break; case PtlOpenMode.PAGE_MODE.PAGE_MODE_USE_THUMBS: // サムネイルパネルとページ Console.WriteLine(" PageMode : Use Thumbs"); break; case PtlOpenMode.PAGE_MODE.PAGE_MODE_USE_OC: // レイヤーパネルとページ Console.WriteLine(" PageMode : Use OC"); break; case PtlOpenMode.PAGE_MODE.PAGE_MODE_USE_ATTACHMENTS: // 添付ファイルパネルとページ Console.WriteLine(" PageMode : Use Atttachments"); break; } // ウィンドウオプションを取得 bool fitwindow = (openmode.getWindowOption() & PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_FIT_WINDOW) == PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_FIT_WINDOW; bool centerwindow = (openmode.getWindowOption() & PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_CENTER_WINDOW) == PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_CENTER_WINDOW; bool fullscreen = (openmode.getWindowOption() & PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_FULL_SCREEN) == PtlOpenMode.WINDOWS_OPTION.WINDOWS_OPTION_FULL_SCREEN; if (fitwindow) { Console.WriteLine(" FitWindow : true"); } else { Console.WriteLine(" FitWindow : false"); } if (centerwindow) { Console.WriteLine(" CenterWindow : true"); } else { Console.WriteLine(" CenterWindow : false"); } if (fullscreen) { Console.WriteLine(" Full Screen : true"); } else { Console.WriteLine(" Full Screen : false"); } // ウィンドウのタイトルバーに文書タイトルを表示するかどうかを取得 if (openmode.getDisplayDocTitle()) { Console.WriteLine(" Display Doc Title : true"); } else { Console.WriteLine(" Display Doc Title : false"); } // ユーザーインターフェイスオプションを取得 int uiopt = (int)openmode.getUIOption(); bool hidemenu = (openmode.getUIOption() & PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_MENUBAR) == PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_MENUBAR; bool hidetool = (openmode.getUIOption() & PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_TOOLBAR) == PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_TOOLBAR; bool hidewinui = (openmode.getUIOption() & PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_WINDOWUI) == PtlOpenMode.UI_OPTION.UI_OPTION_HIDE_WINDOWUI; if (hidemenu) { Console.WriteLine(" Hide Menubar : true"); } else { Console.WriteLine(" Hide Menubar : false"); } if (hidetool) { Console.WriteLine(" Hide Toolbar : true"); } else { Console.WriteLine(" Hide Toolbar : false"); } if (hidewinui) { Console.WriteLine(" Hide Window UI : true"); } else { Console.WriteLine(" Hide Window UI : false"); } // オープンアクションを取得 showAction(openmode.getOpenAction()); // カスタムプロパティを取得 Console.WriteLine(Environment.NewLine); Console.WriteLine("Custom Property"); PtlCustomProperties customProperties = docproperty.getCustomProperties(); int numCustomProperties = customProperties.getCount(); for (int i = 0; i < numCustomProperties; ++i) { PtlCustomProperty prop = customProperties.get(i); Console.WriteLine(" Name : {0}", prop.getName()); Console.WriteLine(" Value : {0}", prop.getValue()); } Console.WriteLine("\n"); Console.WriteLine("Security Information"); bool isEncrypted = doc.isEncrypted(); if (!isEncrypted) { Console.WriteLine(" Not Encrypted."); return; } PtlEncrypt encrypt = doc.getEncrypt(); int filterType = (int)encrypt.getFilterType(); if (filterType != (int)PtlEncrypt.FILTER_TYPE.FILTER_STANDARD) { return; } PtlEncryptStandard encryptStandard = (PtlEncryptStandard)encrypt; Console.WriteLine(" Security Handler : Standard Security"); int keyLength = encrypt.getKeyLength(); Console.WriteLine(" Key Length : {0}", keyLength); int method = (int)encryptStandard.getMethod(); if (method == (int)PtlEncryptStandard.STANDARD_METHOD_TYPE.METHOD_RC4) { Console.WriteLine(" Method = RC4"); } else if (method == (int)PtlEncryptStandard.STANDARD_METHOD_TYPE.METHOD_RC4) { Console.WriteLine(" Method = AES"); } PtlEncryptPermission perms = encryptStandard.getPermission(); switch (perms.getType()) { case PtlEncryptPermission.PERM_TYPE.PERM_TYPE1: { Console.WriteLine(" Permission Type1"); PtlEncryptPermissionType1 perms1 = (PtlEncryptPermissionType1)perms; bool print = perms1.getPrint(); if (print) { Console.WriteLine(" Print : allowed."); } else { Console.WriteLine(" Print : not allowed."); } PtlEncryptPermissionType1.PERMISSION_MODIFY modify = perms1.getModify(); switch (modify) { case PtlEncryptPermissionType1.PERMISSION_MODIFY.PERM_MODIFY_NOT_ALLOWED: Console.WriteLine(" Modify : not allowed."); break; case PtlEncryptPermissionType1.PERMISSION_MODIFY.PERM_MODIFY_ANNOTANDFORM: Console.WriteLine(" Modify : Commenting, filling in form fields, and signing existing signature fields."); break; case PtlEncryptPermissionType1.PERMISSION_MODIFY.PERM_MODIFY_ASSEMBLEANDFORM: Console.WriteLine(" Modify : Page layout, filling in form fields, and signing existing signature fields."); break; case PtlEncryptPermissionType1.PERMISSION_MODIFY.PERM_MODIFY_MODYFYDOC: Console.WriteLine(" Modify : Any except extracting pages."); break; } bool copy = perms1.getCopy(); if (copy) { Console.WriteLine(" Copy : Enable copying of text, images, and other content and access for the visually impaired."); } else { Console.WriteLine(" Copy : Disable copying of text, images, and other content and access for the visually impaired."); } } break; case PtlEncryptPermission.PERM_TYPE.PERM_TYPE2: { Console.WriteLine(" Permission Type2"); PtlEncryptPermissionType2 perms2 = (PtlEncryptPermissionType2)perms; PtlEncryptPermissionType2.PERMISSION_PRINT print = perms2.getPrint(); switch (print) { case PtlEncryptPermissionType2.PERMISSION_PRINT.PERM_PRINT_NOT_ALLOWED: Console.WriteLine(" Print : not allowed."); break; case PtlEncryptPermissionType2.PERMISSION_PRINT.PERM_PRINT_LOW: Console.WriteLine(" Print : Low resolution."); break; case PtlEncryptPermissionType2.PERMISSION_PRINT.PERM_PRINT_HIGH: Console.WriteLine(" Print : High resolution."); break; } PtlEncryptPermissionType2.PERMISSION_MODIFY modify = perms2.getModify(); switch (modify) { case PtlEncryptPermissionType2.PERMISSION_MODIFY.PERM_MODIFY_NOT_ALLOWED: Console.WriteLine(" Modify : not allowed."); break; case PtlEncryptPermissionType2.PERMISSION_MODIFY.PERM_MODIFY_ASSEMBLEDOC: Console.WriteLine(" Modify : Inserting, deleting, and rotating pages."); break; case PtlEncryptPermissionType2.PERMISSION_MODIFY.PERM_MODIFY_FILLFORM: Console.WriteLine(" Modify : Filling in form fields, and signing existing signature fields."); break; case PtlEncryptPermissionType2.PERMISSION_MODIFY.PERM_MODIFY_ANNOTANDFORM: Console.WriteLine(" Modify : Commenting, filling in form fields, and signing existing signature fields."); break; case PtlEncryptPermissionType2.PERMISSION_MODIFY.PERM_MODIFY_MODYFYDOC: Console.WriteLine(" Modify : Any except extracting pages."); break; } bool copy = perms2.getCopy(); if (copy) { Console.WriteLine(" Copy : Enable copying of text, images, and other content."); } else { Console.WriteLine(" Copy : Disable copying of text, images, and other content."); } bool acc = perms2.getAccessibility(); if (acc) { Console.WriteLine(" Accessibility : Enable text access for screen render devices for the visually impaired."); } else { Console.WriteLine(" Accessibility : Disable text access for screen render devices for the visually impaired."); } } break; } Console.WriteLine(Environment.NewLine); Console.WriteLine("Standard Information"); if (doc.isSignatured()) { Console.WriteLine(" Signature : true"); } else { Console.WriteLine(" Signature : false"); } if (doc.isPDFA()) { Console.WriteLine(" PDF/A : true"); } else { Console.WriteLine(" PDF/A : false"); } if (doc.isPDFX()) { Console.WriteLine(" PDF/X : true"); } else { Console.WriteLine(" PDF/X : false"); } } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("\n"); Console.WriteLine("-- 完了 --"); } } public static int showAction(PtlAction action) { try { switch (action.getType()) { case PtlAction.ACTION_TYPE.TYPE_NONE: Console.WriteLine(" Action : none"); break; case PtlAction.ACTION_TYPE.TYPE_UNKNOWN: Console.WriteLine(" Action : unknown"); break; case PtlAction.ACTION_TYPE.TYPE_GOTO: { Console.WriteLine(" Action : GoTo"); PtlActionGoTo actGoTo = (PtlActionGoTo)action; PtlDest dest = actGoTo.getDest(); int ret = showDest(dest); if (ret != 0) { return ret; } } break; case PtlAction.ACTION_TYPE.TYPE_GOTO_R: { Console.WriteLine(" Action : GoToR"); PtlActionGoToR actGoToR = (PtlActionGoToR)action; PtlDest dest = actGoToR.getDest(); int ret = showDest(dest); if (ret != 0) { return ret; } } break; case PtlAction.ACTION_TYPE.TYPE_LAUNCH: { Console.WriteLine(" Action : Launch"); PtlActionLaunch actLaunch = (PtlActionLaunch)action; Console.WriteLine(" file name : {0}", actLaunch.getFileName()); bool flag = actLaunch.getNewWindowFlag(); if (flag) { Console.WriteLine(" new window : true"); } else { Console.WriteLine(" new window : false"); } } break; case PtlAction.ACTION_TYPE.TYPE_URI: { Console.WriteLine(" Action : URI"); PtlActionURI actURI = (PtlActionURI)action; Console.WriteLine(" uri : {0}", actURI.getURI()); } break; } } catch (PtlException e) { Console.WriteLine(" Error Message: {0}", e.getErrorMessage()); Console.WriteLine("\n"); return e.getErrorCode(); } catch (Exception) { Console.WriteLine("Unknown error has occured."); Console.WriteLine("\n"); return -2; } return 0; } public static int showDest(PtlDest dest) { try { PtlDest.DEST_TYPE destType = dest.getType(); int pageNumber = dest.getPageNumber(); switch (destType) { case PtlDest.DEST_TYPE.TYPE_NONE: Console.WriteLine(" Dest : none"); break; case PtlDest.DEST_TYPE.TYPE_XYZ: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : XYZ"); float left = 0.0f; if (!dest.isLeftNull()) left = dest.getLeft(); Console.WriteLine(" left : {0}", left); float top = 0.0f; if (!dest.isTopNull()) top = dest.getTop(); Console.WriteLine(" top : {0}", top); float zoom = 0.0f; if (!dest.isZoomNull()) zoom = dest.getZoom(); Console.WriteLine(" zoom : {0}", zoom); } break; case PtlDest.DEST_TYPE.TYPE_FIT: Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : Fit"); break; case PtlDest.DEST_TYPE.TYPE_FIT_H: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitH"); float top = 0.0f; if (!dest.isTopNull()) top = dest.getTop(); Console.WriteLine(" top : {0}", top); } break; case PtlDest.DEST_TYPE.TYPE_FIT_V: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitV"); float left = 0.0f; if (!dest.isLeftNull()) left = dest.getLeft(); Console.WriteLine(" left : {0}", left); } break; case PtlDest.DEST_TYPE.TYPE_FIT_R: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitR"); float left = 0.0f; if (!dest.isLeftNull()) left = dest.getLeft(); Console.WriteLine(" left : {0}", left); float bottom = 0.0f; if (!dest.isBottomNull()) bottom = dest.getBottom(); Console.WriteLine(" bottom : {0}", bottom); float right = 0.0f; if (!dest.isRightNull()) right = dest.getRight(); Console.WriteLine(" right : {0}", right); float top = 0.0f; if (!dest.isTopNull()) top = dest.getTop(); Console.WriteLine(" top : {0}", top); float zoom = 0.0f; if (!dest.isZoomNull()) zoom = dest.getZoom(); Console.WriteLine(" zoom : {0}", zoom); } break; case PtlDest.DEST_TYPE.TYPE_FIT_B: Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitB"); break; case PtlDest.DEST_TYPE.TYPE_FIT_BH: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitBH"); float top = 0.0f; if (!dest.isTopNull()) top = dest.getTop(); Console.WriteLine(" top : {0}", top); } break; case PtlDest.DEST_TYPE.TYPE_FIT_BV: { Console.WriteLine(" Dest page : {0}", pageNumber); Console.WriteLine(" Dest type : FitBV"); float left = 0.0f; if (!dest.isLeftNull()) left = dest.getLeft(); Console.WriteLine(" left : {0}", left); } break; } } catch (PtlException e) { Console.WriteLine(" Error Message: {0}", e.getErrorMessage()); Console.Write("\n"); return e.getErrorCode(); } catch (Exception) { Console.WriteLine("Unknown error has occured."); Console.Write("\n"); return -2; } return 0; } } }