{"id":5540,"date":"2025-05-28T16:15:52","date_gmt":"2025-05-28T08:15:52","guid":{"rendered":"https:\/\/support.fuxinsoft.cn\/?p=5540"},"modified":"2025-06-10T13:21:25","modified_gmt":"2025-06-10T05:21:25","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8pdf-sdk%e5%ae%9e%e7%8e%b0%e5%b0%86%e7%9f%a9%e5%bd%a2%e6%a1%86%e6%b3%a8%e9%87%8a%e5%86%85%e7%9a%84%e6%89%80%e6%9c%89%e5%86%85%e5%ae%b9%e5%a4%8d%e5%88%b6%e5%88%b0","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=5540","title":{"rendered":"\u9ad8\u6548\u5b9e\u73b0PDF\u77e9\u5f62\u6ce8\u91ca\u533a\u57df\u5185\u5bb9\u63d0\u53d6"},"content":{"rendered":"\n<p>\u7528\u6237\u9700\u6c42\u89e3\u6790\uff1a\u5982\u4f55\u5229\u7528PDF SDK\u7cbe\u51c6\u63d0\u53d6\u77e9\u5f62\u6807\u6ce8\u6846\u5185\u7684\u5168\u90e8\u5185\u5bb9\uff08\u56fe\u6587\u6df7\u6392\uff09\u5e76\u751f\u6210\u65b0PDF\u6587\u6863\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void main(String&#91;] args) throws PDFException {\n        PDFDoc doc = new PDFDoc(\"annot.pdf\");\n            doc.load(null);\n        PDFDoc newdoc = new PDFDoc();\n        doc.load(null);\n        PDFPage page = doc.getPage(0);\n        RectF box = page.getBox(0);\n        PDFPage newPage = newdoc.insertPage(0,1);\n        newPage.setBox(0,box);\n        newPage.startParse(0,null,true);\n\n        newdoc.load(null);\n            \/\/\u62ff\u5230\u77e9\u5f62\u5185\u6240\u6709\u5143\u7d20\uff0c\u590d\u5236\u5230\u7a7a\u767d\u9875\u9762\n\n        \/\/PDFPage pdfPage = doc.insertPage(1, 1);\n        \/\/pdfPage.startParse(0,null,true);\n        page.startParse(0,null,true);\n        int annotCount = page.getAnnotCount();\n        OCR ocr = new OCR();\n        System.out.println(annotCount);\n        for (int i = 0; i &lt; annotCount; i++) {\n            Annot annot = page.getAnnot(i);\n            if(e_Square == annot.getType()){\n                RectF rect = annot.getRect();\n                GraphicsObjectArray graphicsObjectsAtRectangle = page.getGraphicsObjectsAtRectangle(rect, 0);\n                int size = graphicsObjectsAtRectangle.getSize();\n                for (int j = 0; j &lt; size; j++) {\n                    GraphicsObject gObj = graphicsObjectsAtRectangle.getAt(j);\n                    newPage.insertGraphicsObject(newPage.getLastGraphicsObjectPosition(0), gObj.clone(page,newPage));\n                }\n\n\n                newPage.generateContent();\n            }\n        }\n\n        newdoc.saveAs(\"annot_test.pdf\",e_SaveFlagRemoveRedundantObjects);<\/code><\/pre>\n\n\n\n<p><strong>\u6280\u672f\u5b9e\u73b0\u6d41\u7a0b\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u200b\u76ee\u6807\u6ce8\u91ca\u7b5b\u9009\u200b\uff1a\u901a\u8fc7SDK\u904d\u5386\u539f\u59cbPDF\u9996\u9875\u6ce8\u91ca\u5217\u8868\uff0c\u7cbe\u51c6\u5b9a\u4f4de_Square\u7c7b\u578b\uff08\u65b9\u5f62\u6807\u6ce8\u6846\uff09\u7684\u5750\u6807\u533a\u57df<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u56fe\u5f62\u5bf9\u8c61\u63d0\u53d6\u200b\uff1a\u9488\u5bf9\u6bcf\u4e2a\u65b9\u5f62\u6ce8\u91ca\u7684\u8fb9\u754c\u8303\u56f4\uff0c\u667a\u80fd\u6293\u53d6\u533a\u57df\u5185\u6240\u6709\u53ef\u89c6\u5143\u7d20\uff08\u5305\u62ec\u77e2\u91cf\u56fe\u5f62\u3001\u6587\u672c\u56fe\u5c42\u3001\u5d4c\u5165\u56fe\u50cf\u7b49\uff09<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u200b\u5185\u5bb9\u590d\u5236\u5230\u65b0PDF\u200b\uff1a\u5c06\u6355\u83b7\u7684\u89c6\u89c9\u5143\u7d20\u6309\u539f\u59cb\u5750\u6807\u7cfb\u7edf\u65e0\u635f\u79fb\u690d\u5230\u65b0PDF\u753b\u5e03\uff0c\u786e\u4fdd\u50cf\u7d20\u7ea7\u7cbe\u5ea6\u8f93\u51fa\u81f3annot_test.pdf\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u6237\u9700\u6c42\u89e3\u6790\uff1a\u5982\u4f55\u5229\u7528PDF SDK\u7cbe\u51c6\u63d0\u53d6\u77e9\u5f62\u6807\u6ce8\u6846\u5185\u7684\u5168\u90e8\u5185\u5bb9\uff08\u56fe\u6587\u6df7\u6392\uff09\u5e76\u751f\u6210\u65b0PDF\u6587\u6863\uff1f \u6280\u672f\u5b9e\u73b0\u6d41 [&hellip;]<\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[457,377,626,628,627,675,374,676,674],"class_list":["post-5540","post","type-post","status-publish","format-standard","hentry","category-gsdk","tag-457","tag-377","tag-626","tag-628","tag-pdf","tag-675","tag-374","tag-676","tag-674"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/5540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5540"}],"version-history":[{"count":2,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/5540\/revisions"}],"predecessor-version":[{"id":5600,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/5540\/revisions\/5600"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}