{"id":5861,"date":"2015-07-22T15:42:42","date_gmt":"2015-07-22T06:42:42","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=5861"},"modified":"2015-07-22T15:52:28","modified_gmt":"2015-07-22T06:52:28","slug":"powershellitextsharp%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6pdf%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e7%b5%90%e5%90%88%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=5861","title":{"rendered":"[PowerShell]iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/www.moug.net\/\" title=\"Excel VBA \u3092\u5b66\u3076\u306a\u3089 moug \u30e2\u30fc\u30b0\" target=\"_blank\">moug<\/a>\u306b\u3042\u3063\u305f\u8cea\u554f\u300c<a href=\"http:\/\/www.moug.net\/faq\/viewtopic.php?t=72323\" title=\"Excel VBA \u3092\u5b66\u3076\u306a\u3089 moug \u30e2\u30fc\u30b0\uff5cExcel \uff08VBA\uff09\uff5c\uff12\u3064\u306ePDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b\u306b\u306f\" target=\"_blank\">\uff12\u3064\u306ePDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b\u306b\u306f<\/a>\u300d\u306e\u56de\u7b54\u7528\u306b\u66f8\u3044\u305f\u3001PowerShell\u304b\u3089<a href=\"http:\/\/sourceforge.net\/projects\/itextsharp\/\" title=\"iTextSharp, a .NET PDF library | SourceForge.net\" target=\"_blank\">iTextSharp<\/a>\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">&#x5B;System.Reflection.Assembly]::LoadFrom(&quot;C:\\System\\iTextSharp\\itextsharp.dll&quot;);\r\n$reader1 = New-Object iTextSharp.text.pdf.PdfReader(&quot;C:\\Test\\Sample01.pdf&quot;);\r\n$reader2 = New-Object iTextSharp.text.pdf.PdfReader(&quot;C:\\Test\\Sample02.pdf&quot;);\r\n$fs = New-Object System.IO.FileStream(&quot;C:\\Test\\Output.pdf&quot;, &#x5B;System.IO.FileMode]::OpenOrCreate);\r\n$copy = New-Object iTextSharp.text.pdf.PdfCopyFields($fs);\r\n$copy.AddDocument($reader1);\r\n$copy.AddDocument($reader2);\r\n$copy.Close();\r\n$fs.Close();\r\n$reader1.Close();\r\n$reader2.Close();<\/pre>\n<p>iTextSharp\u306fPowerShell\u304b\u3089\u3082\u7c21\u5358\u306b\u4f7f\u3048\u3066\u4fbf\u5229\u3067\u3059\u306d\uff01<br \/>\n\u3061\u306a\u307f\u306b\u3001\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092VBA\u304b\u3089<span style=\"color: #ff0000; font-weight: bold;\">-Command<\/span>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4f7f\u3063\u3066\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u306e\u304c\u4e0b\u8a18\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample()\r\n  Dim v As Variant '\u7d50\u5408\u5143PDF\u30d5\u30a1\u30a4\u30eb\r\n  \r\n  v = Array( _\r\n        &quot;C:\\Test\\Sample01.pdf&quot;, _\r\n        &quot;C:\\Test\\Sample02.pdf&quot;, _\r\n        &quot;C:\\Test\\Sample03.pdf&quot; _\r\n      )\r\n  MergePDF v, &quot;C:\\Test\\Output.pdf&quot;\r\nEnd Sub\r\n\r\nPrivate Sub MergePDF(ByVal InputFilePath As Variant, _\r\n                     ByVal OutputFilePath As String)\r\n'iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\r\n  Dim com As String\r\n  Dim i As Long\r\n  Const DllFilePath As String = &quot;C:\\System\\iTextSharp\\itextsharp.dll&quot; 'itextsharp.dll\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\r\n  \r\n  com = &quot;powershell -Command &quot;\r\n  com = com &amp; &quot;&#x5B;System.Reflection.Assembly]::LoadFrom('&quot; &amp; DllFilePath &amp; &quot;');&quot;\r\n  For i = LBound(InputFilePath) To UBound(InputFilePath)\r\n    com = com &amp; &quot;$reader&quot; &amp; i &amp; &quot; = New-Object iTextSharp.text.pdf.PdfReader('&quot; &amp; InputFilePath(i) &amp; &quot;');&quot;\r\n  Next\r\n  com = com &amp; &quot;$fs = New-Object System.IO.FileStream('&quot; &amp; OutputFilePath &amp; &quot;', &#x5B;System.IO.FileMode]::OpenOrCreate);&quot;\r\n  com = com &amp; &quot;$copy = New-Object iTextSharp.text.pdf.PdfCopyFields($fs);&quot;\r\n  For i = LBound(InputFilePath) To UBound(InputFilePath)\r\n    com = com &amp; &quot;$copy.AddDocument($reader&quot; &amp; i &amp; &quot;);&quot;\r\n  Next\r\n  com = com &amp; &quot;$copy.Close();&quot;\r\n  com = com &amp; &quot;$fs.Close();&quot;\r\n  For i = LBound(InputFilePath) To UBound(InputFilePath)\r\n    com = com &amp; &quot;$reader&quot; &amp; i &amp; &quot;.Close();&quot;\r\n  Next\r\n  VBA.Shell com, vbNormalNoFocus\r\nEnd Sub<\/pre>\n<p>\u30d0\u30c3\u30c1\u51e6\u7406\u3092\u884c\u3046\u306e\u3067\u3042\u308c\u3070PowerShell\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u3051\u3070\u826f\u3044\u306e\u3067\u3001\u6562\u3048\u3066VBA\u3092\u4f7f\u3046\u5fc5\u8981\u306f\u7121\u3055\u305d\u3046\u3067\u3059\u304c\u3001\u65e2\u5b58\u306e\u30de\u30af\u30ed\u306bPDF\u30d5\u30a1\u30a4\u30eb\u306e\u7d50\u5408\u51e6\u7406\u3092\u7d44\u307f\u8fbc\u307f\u305f\u3044\u3068\u304d\u306b\u306f\u4f7f\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<h4 class=\"style4a\">\u53c2\u8003Web\u30da\u30fc\u30b8<\/h4>\n<ul>\n<li>Hello, iTextSharp! &#8211; Life like a clown<\/li>\n<li style=\"list-style-type:none;\"><a href=\"http:\/\/d.hatena.ne.jp\/tt_clown\/20111104\/itext_sharp\" target=\"_blank\" title=\"Hello, iTextSharp! - Life like a clown\">http:\/\/d.hatena.ne.jp\/tt_clown\/20111104\/itext_sharp<\/a><\/li>\n<\/ul>\n<h4 class=\"style4a\">\u95a2\u9023Web\u30da\u30fc\u30b8<\/h4>\n<ul>\n<li>[PowerShell]iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u306e\u30da\u30fc\u30b8\u6570\u3092\u53d6\u5f97\u3059\u308b<\/li>\n<li style=\"list-style-type:none;\"><a href=\"\/\/www.ka-net.org\/blog\/?p=2317\" target=\"_blank\" title=\"[PowerShell]iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u306e\u30da\u30fc\u30b8\u6570\u3092\u53d6\u5f97\u3059\u308b\">\/\/www.ka-net.org\/blog\/?p=2317<\/a><\/li>\n<li>Acrobat\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308bVBA\u30de\u30af\u30ed<\/li>\n<li style=\"list-style-type:none;\"><a href=\"\/\/www.ka-net.org\/blog\/?p=5866\" target=\"_blank\" title=\"Acrobat\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308bVBA\u30de\u30af\u30ed\">\/\/www.ka-net.org\/blog\/?p=5866<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"moug\u306b\u3042\u3063\u305f\u8cea\u554f\u300c\uff12\u3064\u306ePDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b\u306b\u306f\u300d\u306e\u56de\u7b54\u7528\u306b\u66f8\u3044\u305f\u3001PowerShell\u304b\u3089iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\u3002 &#x5B;System.Reflection.Ass [&hellip;]","protected":false},"author":1,"featured_media":7122,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"iTextSharp\u306f\u624b\u8efd\u3067\u4fbf\u5229\u3067\u3059\u3002 [[PowerShell]iTextSharp\u3092\u4f7f\u3063\u3066PDF\u30d5\u30a1\u30a4\u30eb\u3092\u7d50\u5408\u3059\u308b]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,5],"tags":[],"class_list":["post-5861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-other"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Other.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1wx","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5861"}],"version-history":[{"count":3,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5861\/revisions"}],"predecessor-version":[{"id":5868,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5861\/revisions\/5868"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7122"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}