{"id":203166,"date":"2025-05-22T08:15:39","date_gmt":"2025-05-22T00:15:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203166\/"},"modified":"2025-05-22T08:15:39","modified_gmt":"2025-05-22T00:15:39","slug":"java-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%b0%86-xml-%e8%bd%ac%e6%8d%a2%e4%b8%ba-pdf%ef%bc%8c%e5%b9%b6%e5%ae%9e%e7%8e%b0-doc-%e5%88%b0-pdf-%e7%9a%84%e8%bd%ac%e6%8d%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203166\/","title":{"rendered":"Java \u4e2d\u5982\u4f55\u5c06 XML \u8f6c\u6362\u4e3a PDF\uff0c\u5e76\u5b9e\u73b0 DOC \u5230 PDF \u7684\u8f6c\u6362\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java \u4e2d\u5982\u4f55\u5c06 XML \u8f6c\u6362\u4e3a PDF\uff0c\u5e76\u5b9e\u73b0 DOC \u5230 PDF \u7684\u8f6c\u6362\uff1f<\/h1>\n<p>\u6765\u5230\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aJava \u4e2d\u5982\u4f55\u5c06 XML \u8f6c\u6362\u4e3a PDF\uff0c\u5e76\u5b9e\u73b0 DOC \u5230 PDF \u7684\u8f6c\u6362\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241031\/17303360916722d55b1b410.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>xml \u8f6c word \u518d\u8f6c pdf \u7684 java \u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5df2\u77e5\u5982\u4f55\u5728 linux \u7cfb\u7edf\u7684 java \u7a0b\u5e8f\u4e2d\u5c06 xml \u8f6c\u6362\u4e3a doc \u6587\u4ef6\uff0c\u4f46\u9700\u8981\u8fdb\u4e00\u6b65\u5c06 doc \u6587\u4ef6\u8f6c\u6362\u4e3a pdf \u6587\u4ef6\u3002\u5b9e\u73b0\u6b64\u8f6c\u6362\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p><strong>1. \u5bfc\u5165 jodconverter \u5e93<\/strong><\/p>\n<p>\u5c06 jodconverter \u5e93\u6dfb\u52a0\u5230\u60a8\u7684 java \u9879\u76ee\u4e2d\uff0c\u8be5\u5e93\u7528\u4e8e\u5728 java \u5e94\u7528\u7a0b\u5e8f\u4e2d\u64cd\u4f5c openoffice \u548c libreoffice\u3002<\/p>\n<p><strong>2. \u5b9e\u4f8b\u5316 opendocumentconverter<\/strong><\/p>\n<pre>import com.sun.star.uno.xcomponentcontext;\nimport com.sun.star.lib.uno.helper.factory;\nimport com.sun.star.frame.xcomponentloader;\nimport com.sun.star.beans.propertyvalue;\nimport com.sun.star.lang.xmulticomponentfactory;\nimport com.sun.star.lang.xcomponent;\n\n\/\/ ...\n\nopenofficeconnection connection = new openofficeconnection( ... );\nxmulticomponentfactory servicemanager = connection.getservicemanager();\n\nxcomponentcontext xcontext = servicemanager.createinstancewithcontext(\n    \"com.sun.star.frame.desktop\", xcontext);\n\nxcomponentloader xcomponentloader = (xcomponentloader)\n    factory.createcomponent(\"com.sun.star.frame.desktop\", xcontext);<\/pre>\n<p><strong>3. \u52a0\u8f7d doc \u6587\u4ef6<\/strong><\/p>\n<pre>url fileurl = new url(\"file:\/\/\/path\/to\/file.doc\");\npropertyvalue[] loadproperties = new propertyvalue[1];\nloadproperties[0] = new propertyvalue();\nloadproperties[0].name = \"hidden\";\nloadproperties[0].value = true;\n\nxcomponent xcomponent = xcomponentloader.loadcomponentfromurl(\n    fileurl.tostring(), \"_blank\", 0, loadproperties);<\/pre>\n<p><strong>4. \u8f6c\u6362 doc \u4e3a pdf<\/strong><\/p>\n<pre>PropertyValue[] pdfProperties = new PropertyValue[1];\npdfProperties[0] = new PropertyValue();\npdfProperties[0].Name = \"FilterName\";\npdfProperties[0].Value = \"writer_pdf_Export\";\n\nxComponent.storeAsURL(\"file:\/\/\/path\/to\/output.pdf\", pdfProperties);\n\nxComponent.dispose();\nconnection.dispose();<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528 jodconverter \u5e93\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 xml \u8f6c\u6362\u4e3a doc\uff0c\u7136\u540e\u5c06 doc \u8f6c\u6362\u4e3a pdf\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aJava \u4e2d\u5982\u4f55\u5c06 XML \u8f6c\u6362\u4e3a PDF\uff0c\u5e76\u5b9e\u73b0 DOC \u5230 PDF \u7684\u8f6c\u6362\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u4e2d\u5982\u4f55\u5c06 XML \u8f6c\u6362&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203166","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203166"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203166\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}