{"id":7654,"date":"2025-12-30T16:57:32","date_gmt":"2025-12-30T08:57:32","guid":{"rendered":"https:\/\/support.fuxinsoft.cn\/?p=7654"},"modified":"2025-12-31T14:46:55","modified_gmt":"2025-12-31T06:46:55","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%a4%9a%e4%b8%aa%e8%a1%a8%e5%8d%95pdf%e5%a1%ab%e5%85%85%e6%95%b0%e6%8d%ae%e5%90%8e%e5%90%88%e5%b9%b6%e4%b8%ba%e4%b8%80%e4%b8%aapdf%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=7654","title":{"rendered":"\u5982\u4f55\u5c06\u591a\u4e2a\u8868\u5355PDF\u586b\u5145\u6570\u636e\u540e\u5408\u5e76\u4e3a\u4e00\u4e2aPDF\u6587\u4ef6\uff1f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>var fileUrlList = &#091;\".\/file1.pdf\", \".\/file2.pdf\", \".\/file3.pdf\"];\nvar xmlUrlList = &#091;\".\/file1.xml\", \".\/file2.xml\", \".\/file3.xml\"];\nvar xmlDataList = &#091;];\n\n\/\/\u5c06xmlUrlList\u4e2d\u7684xml\u6587\u4ef6\u5730\u5740\u9010\u4e00\u53d6\u51fa\uff0c\u5e76\u83b7\u53d6\u5bf9\u5e94\u7684xml\u6570\u636e\uff0c\u4f9d\u6b21\u5b58\u5165xmlDataList\u6570\u7ec4\u4e2d\uff0cindex\u7d22\u5f15\u4ece0\u5f00\u59cb\nfunction generateXmlDataArray(xmlUrlList, index) {\n    console.log(xmlUrlList.length);\n    if (index &gt; xmlUrlList.length - 1) {\n        return console.log(\"Finished\");\n    }\n\n    fetch(xmlUrlList&#091;index])\n        .then(response =&gt; {\n            if (!response.ok) {\n                throw new Error(`HTTP error! status: ${response.status}`);\n            }\n            return response.arrayBuffer();\n        })\n        .then(array_buffer =&gt; {\n            xmlDataList&#091;index] = array_buffer;\n            console.log(array_buffer);\n\n            index++;\n            generateXmlDataArray(xmlUrlList, index);\n        })\n        .catch(error =&gt; console.error('There has been a problem with your fetch operation:', error));\n}\nvar curDoc,pageCnt1,pageCnt2;\n\/\/\u5c06\u6587\u4ef6\u5217\u8868\u4e2d\u7684\u6240\u6709PDF\uff0c\u6309\u7167\u6570\u7ec4\u7d22\u5f15\u4ece\u5927\u5230\u5c0f\uff0c\u4f9d\u6b21\u8fdb\u884c\u5408\u5e76\nfunction mergePdfFiles(fileUrlList,xmlDataList,index){\n    \/\/ console.log(fileUrlList.length);\n    if(index &gt; fileUrlList.length-1){\n        \/\/ pdfui.reopenPDFDoc(cccDoc);\n        return console.log(\"Finished\");\n    }\n\n    pdfui.loadPDFDocByHttpRangeRequest({\n        range: {\n            url: fileUrlList&#091;index]\n        }\n    }).then(pdfdoc =&gt; {\n        pdfdoc.loadPDFForm();\n        pdfdoc.importFormFromFile(xmlDataList&#091;index], PDF.constant.File_Type.xml);\n        pdfdoc.flatten(1).then(ret =&gt;{\n            console.log(`file ${index} flattened.`);\n            if(index == 0){\n                pdfui.reopenPDFDoc(pdfdoc).then(newDoc =&gt;{\n                    cccDoc = newDoc;\n                    \/\/ pageCnt1 = cccDoc.getPageCount();\n\n                    index++;\n                    openDocsArray(fileUrlList,xmlDataList,index)\n                });\n            }else{\n                pdfdoc.getFile().then(fileStream =&gt;{\n                    console.log(fileStream);\n                    pageCnt1 = cccDoc.getPageCount();\n                    pageCnt2 = pdfdoc.getPageCount();\n                    console.log(pageCnt1,pageCnt2);\n\n                    cccDoc.insertPages({\n                        destIndex: Number(pageCnt1),\n                        file: fileStream,\n                        \/\/ password: '',\n                        \/\/ flags: 0,\n                        \/\/ layerName: 'layerName',\n                        startIndex: 0,\n                        endIndex: Number(pageCnt2)\n                    }).then(pageArray =&gt;{\n                        index++;\n                        openDocsArray(fileUrlList,xmlDataList,index);\n                    });\n                })\n            }\n        });\n\n    });\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>generateXmlDataArray(xmlUrlList, 0)\nmergePdfFiles(fileUrlList,xmlDataList,0)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9a8c\u8bc1\uff1a<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[251,1185,217],"class_list":["post-7654","post","type-post","status-publish","format-standard","hentry","category-websdk","tag-251","tag-1185","tag-217"],"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\/7654","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\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7654"}],"version-history":[{"count":1,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7654\/revisions"}],"predecessor-version":[{"id":7723,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/7654\/revisions\/7723"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}