{"id":136,"date":"2017-03-01T12:14:03","date_gmt":"2017-03-01T04:14:03","guid":{"rendered":"http:\/\/www.itcat.vip\/?p=136"},"modified":"2017-03-01T12:14:03","modified_gmt":"2017-03-01T04:14:03","slug":"%e4%bd%bf%e7%94%a8apachepdfbox-%e8%bf%9b%e8%a1%8cpdf-%e8%a1%a8%e5%8d%95%e5%a1%ab%e5%85%85","status":"publish","type":"post","link":"https:\/\/www.itcat.vip\/?p=136","title":{"rendered":"\u4f7f\u7528apache\/pdfbox \u8fdb\u884cPDF \u8868\u5355\u586b\u5145"},"content":{"rendered":"<p>\u573a\u666f\u8bf4\u660e\uff1a\u5728\u67d0\u4e2a\u9879\u76ee\u4e2d\uff0c\u9700\u8981\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u586b\u5199W8\/W9 \u7a0e\u8868\uff0c\u5e76\u4e14\u4fdd\u5b58\u6210\u65b0PDF\u6587\u4ef6\u7684\u529f\u80fd\u3002\u5176\u4e2dW8\/W9 \u7a0e\u8868\u662f\u4e00\u4e2a\u5e26\u4ea4\u4e92\u5f0f\u8868\u5355\u7684PDF\u6587\u4ef6\u3002<\/p>\n<p>\u6d89\u53ca\u5de5\u5177\uff1aapache\/pdfbox\uff08https:\/\/pdfbox.apache.org\/index.html\uff09\u3001Adobe Acrobat<\/p>\n<p>\u5b9e\u73b0\u65b9\u5f0f\uff1a<\/p>\n<p>1.\u9996\u5148\u5f97\u77e5\u9053PDF\u4e2d\u7684\u8868\u5355\u57df\u540d\u79f0\uff0c\u6b64\u65f6\u4f7f\u7528Adobe Acrobat \u7684\u8868\u5355 \u201c\u5bfc\u51fa\u6570\u636e\u201d\u529f\u80fd\uff0c\u5bfc\u51faXML\u6587\u4ef6\uff0c\u53ef\u4ece\u4e2d\u5f97\u77e5\u8868\u5355\u57df\u540d\u79f0\u3002<\/p>\n<p>\u4ee5W8 \u4e3a\u4f8b\uff1a<\/p>\n<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<\/p>\n<p>&lt;topmostSubform&gt;<br \/>\n&lt;Pg1Header xmlns:xfa=&#8221;http:\/\/www.xfa.org\/schema\/xfa-data\/1.0\/&#8221; xfa:dataNode=&#8221;dataGroup&#8221;&gt;&lt;\/Pg1Header&gt;<br \/>\n&lt;DoNotUseChart xmlns:xfa=&#8221;http:\/\/www.xfa.org\/schema\/xfa-data\/1.0\/&#8221; xfa:dataNode=&#8221;dataGroup&#8221;&gt;&lt;\/DoNotUseChart&gt;<br \/>\n&lt;PartI xmlns:xfa=&#8221;http:\/\/www.xfa.org\/schema\/xfa-data\/1.0\/&#8221; xfa:dataNode=&#8221;dataGroup&#8221;&gt;&lt;\/PartI&gt;<br \/>\n&lt;p1-t1\/&gt;<br \/>\n&lt;p1-t2\/&gt;<br \/>\n&lt;p1-t3\/&gt;<br \/>\n&lt;p1-t4\/&gt;<br \/>\n&lt;p1-t5\/&gt;<br \/>\n&lt;p1-t6\/&gt;<br \/>\n&lt;p1-t7\/&gt;<br \/>\n&lt;p1-t8\/&gt;<br \/>\n&lt;p1-t9\/&gt;<br \/>\n&lt;p1-t10\/&gt;<br \/>\n&lt;p1-t11\/&gt;<br \/>\n&lt;p1-t12\/&gt;<br \/>\n&lt;PartII xmlns:xfa=&#8221;http:\/\/www.xfa.org\/schema\/xfa-data\/1.0\/&#8221; xfa:dataNode=&#8221;dataGroup&#8221;&gt;&lt;\/PartII&gt;<br \/>\n&lt;p1-t13\/&gt;<br \/>\n&lt;p1-t16\/&gt;<br \/>\n&lt;p1-t15\/&gt;<br \/>\n&lt;p1-t17\/&gt;<br \/>\n&lt;p1-t18\/&gt;<br \/>\n&lt;p1-t19\/&gt;<br \/>\n&lt;p1-t20\/&gt;<br \/>\n&lt;PartIII xmlns:xfa=&#8221;http:\/\/www.xfa.org\/schema\/xfa-data\/1.0\/&#8221; xfa:dataNode=&#8221;dataGroup&#8221;&gt;&lt;\/PartIII&gt;<br \/>\n&lt;p1-t21\/&gt;<br \/>\n&lt;p1-t22\/&gt;<br \/>\n&lt;\/topmostSubform&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>2.\u4f7f\u7528pdfbox \u8fdb\u884c\u8868\u5355\u586b\u5145\uff0cdemo\u5982\u4e0b\uff1a<\/p>\n<p>\/**<br \/>\n* Example to show filling form fields.<br \/>\n*<br \/>\n*\/<br \/>\npublic final class FillFormField<br \/>\n{<br \/>\nprivate FillFormField()<br \/>\n{<br \/>\n}<\/p>\n<p>public static void main(String[] args) throws IOException<br \/>\n{<br \/>\nString formTemplate = &#8220;src\/main\/resources\/org\/apache\/pdfbox\/examples\/interactive\/form\/FillFormField.pdf&#8221;;<\/p>\n<p>\/\/ load the document<br \/>\nPDDocument pdfDocument = PDDocument.load(new File(formTemplate));<\/p>\n<p>\/\/ get the document catalog<br \/>\nPDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();<\/p>\n<p>\/\/ as there might not be an AcroForm entry a null check is necessary<br \/>\nif (acroForm != null)<br \/>\n{<br \/>\n\/\/ Retrieve an individual field and set its value.<br \/>\nPDTextField field = (PDTextField) acroForm.getField( &#8220;sampleField&#8221; );<br \/>\nfield.setValue(&#8220;Text Entry&#8221;);<\/p>\n<p>\/\/ If a field is nested within the form tree a fully qualified name<br \/>\n\/\/ might be provided to access the field.<br \/>\nfield = (PDTextField) acroForm.getField( &#8220;fieldsContainer.nestedSampleField&#8221; );<br \/>\nfield.setValue(&#8220;Text Entry&#8221;);<br \/>\n}<\/p>\n<p>\/\/ Save and close the filled out form.<br \/>\npdfDocument.save(&#8220;target\/FillFormField.pdf&#8221;);<br \/>\npdfDocument.close();<br \/>\n}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u573a\u666f\u8bf4\u660e\uff1a\u5728\u67d0\u4e2a\u9879\u76ee\u4e2d\uff0c\u9700\u8981\u5f00\u53d1\u4e00\u4e2a\u5728\u7ebf\u586b\u5199W8\/W9 \u7a0e\u8868\uff0c\u5e76\u4e14\u4fdd\u5b58\u6210\u65b0PDF\u6587\u4ef6\u7684\u529f\u80fd\u3002\u5176\u4e2dW8\/W9 \u7a0e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-php-2"],"_links":{"self":[{"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":1,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":137,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/137"}],"wp:attachment":[{"href":"https:\/\/www.itcat.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itcat.vip\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}