{"id":175,"date":"2017-07-24T04:13:52","date_gmt":"2017-07-23T19:13:52","guid":{"rendered":"https:\/\/jidouka.work\/?p=175"},"modified":"2017-12-10T12:11:34","modified_gmt":"2017-12-10T03:11:34","slug":"%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%83%a9%e3%82%a4%e3%83%b3%e3%81%a7pdf%e3%81%ae%e7%b5%90%e5%90%88%e3%82%92%e8%a1%8c%e3%81%86powershell","status":"publish","type":"post","link":"https:\/\/jidouka.work\/?p=175","title":{"rendered":"\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067PDF\u306e\u7d50\u5408\u3092\u884c\u3046[PowerShell]"},"content":{"rendered":"<p>Windows\u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067PDF\u3092\u51e6\u7406\u3059\u308b\u306b\u306f<\/p>\n<ul>\n<li>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5bfe\u5fdc\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b\u3002\uff08pdftk.exe\uff09<\/li>\n<li>PowerShell\u3067PDF\u3092\u64cd\u4f5c\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3002\uff08iTextSharp\uff09<\/li>\n<\/ul>\n<p>\u306e2\u3064\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3069\u3061\u3089\u3067\u3082\u64cd\u4f5c\u611f\u3084\u6a5f\u80fd\u306b\u5dee\u306f\u306a\u304f\u3001\u81ea\u52d5\u5316\u3092\u3059\u308b\u4e0a\u3067\u306f\u969c\u58c1\u3068\u306a\u3089\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306fPowerShell\u3067PDF\u306e\u51e6\u7406\u304c\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u305f\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>iTextSharp\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>iTextSharp\u306f\u4ee5\u4e0b\u306eURL\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>iTextSharp, a .NET PDF library | SourceForge.net<br \/>\n<a href=\"https:\/\/sourceforge.net\/projects\/itextsharp\/\">https:\/\/sourceforge.net\/projects\/itextsharp\/<\/a><\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u306f\u8272\u3005\u3068\u5165\u3063\u3066\u304a\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u306e\u307f\u3068\u3044\u3046\u3053\u3068\u3067\u3001&#8221;itextsharp-dll-core&#8221;\u306e\u307f\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\nitextsharp-dll-core\u3092\u5c55\u958b\u3057\u3066\u30d5\u30a9\u30eb\u30c0\u3092C\u30c9\u30e9\u30a4\u30d6\u76f4\u4e0b\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3057\u305f\u3002\u7f6e\u304f\u5834\u6240\u306f\u3069\u3053\u3067\u3082\u826f\u3044\u3067\u3059\u304c\u3001\u4e2d\u306eDLL\u30d5\u30a1\u30a4\u30eb\u306fPowerShell\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<h2>DLL\u8aad\u307f\u8fbc\u307f\u306e\u30a8\u30e9\u30fc<\/h2>\n<p>Windows\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u6319\u52d5\u304c\u9055\u3046\u306e\u304b\u3001Windows10\u3067\u306fDLL\u3092\u7f6e\u3044\u305f\u3060\u3051\u3067\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u5b9f\u884c\u6642\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002<\/p>\n<blockquote><p>&#8220;1&#8221; \u500b\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3057\u3066 &#8220;LoadFrom&#8221; \u3092\u547c\u3073\u51fa\u3057\u4e2d\u306b\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3057\u305f: &#8220;\u30d5\u30a1\u30a4\u30eb\u307e\u305f\u306f\u30a2\u30bb\u30f3\u30d6\u30ea &#8216;file:\/\/\/C:\\itextsharp-dll-core\\itextsharp.dll&#8217;\u3001\u307e\u305f\u306f\u305d\u306e\u4f9d\u5b58\u95a2\u4fc2\u306e 1 \u3064\u304c\u8aad\u307f\u8fbc\u3081\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u64cd\u4f5c\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u307e\u305b\u3093\u3002 (HRE<br \/>\nSULT \u304b\u3089\u306e\u4f8b\u5916:0x80131515)&#8221;<br \/>\n\u767a\u751f\u5834\u6240 C:\\Users\\usuikanae\\Documents\\PowerShell Practice\\pdf_control\\joint_pdf.ps1:2 \u6587\u5b57:1<br \/>\n+ [System.Reflection.Assembly]::LoadFrom(&#8220;C:\\itextsharp-dll-core\\itexts &#8230;<br \/>\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br \/>\n+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException<br \/>\n+ FullyQualifiedErrorId : FileLoadException<\/p><\/blockquote>\n<p>\u3069\u3046\u3082\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f\u5f97\u4f53\u306e\u77e5\u308c\u306a\u3044DLL\u306f\u3042\u3089\u304b\u3058\u3081OS\u304c\u5229\u7528\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u30d6\u30ed\u30c3\u30af\u3057\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u30d7\u30ed\u30d1\u30c6\u30a3\u304b\u3089\u30d6\u30ed\u30c3\u30af\u306e\u89e3\u9664\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/082421fcdc1a10ca3ab863e2e4b3d079.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-178\" src=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/082421fcdc1a10ca3ab863e2e4b3d079-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/082421fcdc1a10ca3ab863e2e4b3d079-225x300.jpg 225w, https:\/\/jidouka.work\/wp-content\/uploads\/2017\/07\/082421fcdc1a10ca3ab863e2e4b3d079.jpg 463w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<h2>PDF\u306e\u7d50\u5408\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u30b3\u30fc\u30c9<\/h2>\n<figure class=\"jd-code\"><figcaption>PDF\u7d50\u5408<\/figcaption><button type=\"button\" class=\"jd-code-copy\">\u30b3\u30d4\u30fc<\/button><pre><code class=\"language-powershell\">#itextsharp.dll\u306e\u30ed\u30fc\u30c9\r\n[System.Reflection.Assembly]::LoadFrom(&quot;C:\\itextsharp-dll-core\\itextsharp.dll&quot;);\r\n\r\n#\u73fe\u5728\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u53d6\u5f97\r\n$currentDir = Get-Location\r\nSet-Location $currentDir\r\n\r\n\r\n#\u51fa\u529b\u7528\u306e\u65b0\u3057\u3044PDF\u3092\u73fe\u5728\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4f5c\u6210\r\n$newPdfPath = Join-Path $currentDir &quot;new.pdf&quot;\r\n$fileStream = New-Object System.IO.FileStream($newPdfPath, [System.IO.FileMode]::OpenOrCreate);\r\n$newPdf = New-Object iTextSharp.text.pdf.PdfCopyFields($fileStream);\r\n\r\n#\u5f15\u6570\u306epdf\u66f8\u985e\u3092\u53d6\u5f97\r\nforeach($file in $args) {\r\n\r\n    #\u5f15\u6570\u306b\u73fe\u5728\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u7d50\u5408\r\n    $filePath = Convert-Path $file\r\n    \r\n    #\u7d50\u5408\u3059\u308bPDF\u3092\u8aad\u307f\u8fbc\u3080\r\n    $pdf = New-Object iTextSharp.text.pdf.PdfReader($filePath);\r\n\r\n    #\u65b0\u3057\u3044PDF\u30d5\u30a1\u30a4\u30eb\u306b\u65e2\u5b58\u306ePDF\u3092\u8ffd\u52a0\r\n    $newPdf.AddDocument($pdf);\r\n\r\n}\r\n\r\n#newPdf\u306eClose\r\n$newPdf.Close();\r\n\r\n#fileStream\u306eClose\r\n$fileStream.Close();\r\n\r\n<\/code><\/pre><\/figure>\n<p>\u5b9f\u884c\u6642\u306b\u5f15\u6570\u3068\u3057\u3066\u7d50\u5408\u3057\u305f\u3044PDF\u30d5\u30a1\u30a4\u30eb\u3092\u5168\u3066\u6307\u5b9a\u3059\u308b\u3068\u5168\u3066\u7d50\u5408\u3055\u308c\u305fPDF\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows\u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067PDF\u3092\u51e6\u7406\u3059\u308b\u306b\u306f \u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5bfe\u5fdc\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u7528\u3059\u308b &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7],"tags":[6],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-powershell","category-windows","tag-pdf"],"_links":{"self":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":5,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/jidouka.work\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jidouka.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}