{"id":3167,"date":"2024-10-24T15:34:07","date_gmt":"2024-10-24T07:34:07","guid":{"rendered":"https:\/\/support.foxitsoftware.cn\/?p=3167"},"modified":"2025-12-01T16:50:44","modified_gmt":"2025-12-01T08:50:44","slug":"%e5%a6%82%e4%bd%95%e4%bc%b0%e7%ae%97%e6%96%87%e6%9c%ac%e5%af%b9%e8%b1%a1%e4%b9%8b%e9%97%b4%e7%9a%84%e7%a9%ba%e6%a0%bc%e4%b8%aa%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=3167","title":{"rendered":"\u5982\u4f55\u4f30\u7b97\u6587\u672c\u5bf9\u8c61\u4e4b\u95f4\u7684\u7a7a\u683c\u4e2a\u6570\uff1f"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"3167\" class=\"elementor elementor-3167\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-70c5d19e e-flex e-con-boxed e-con e-parent\" data-id=\"70c5d19e\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-c87b992 e-con-full e-flex e-con e-child\" data-id=\"c87b992\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-7aa4572 elementor-widget elementor-widget-text-editor\" data-id=\"7aa4572\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>PDF\u9875\u9762\u4e0a\u4eba\u773c\u770b\u89c1\u7684\u4e00\u884c\u6587\u672c\uff0c\u53ef\u80fd\u662f\u7531\u591a\u4e2a\u72ec\u7acb\u7684\u6587\u672c\u5bf9\u8c61TextObject\u6784\u6210\uff0c<\/p>\n<p><br \/>\u5982\u679c\u9700\u8981\u81ea\u884c\u5c06\u6587\u672c\u5bfc\u51fa\uff0c\u4e3atxt\u7eaf\u6587\u672c\u7684\u683c\u5f0f\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7TextPage.GetTextInRect()\u83b7\u53d6\u3002\u4f46\u8fd9\u4e2a\u63a5\u53e3\u6700\u591a\u53ea\u4fdd\u7559\u6587\u672c\u95f4\u7684\u4e00\u4e2a\u7a7a\u683c\u7b26\u3002\u5982\u679c\u8981\u6c42\u8fd8\u51c6\u786e\u539f\u7a7a\u683c\u95f4\u8ddd\uff0c\u4fdd\u7559\u591a\u4e2a\u7a7a\u683c\uff0c\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u8fdb\u884c\u4f30\u7b97\uff08\u4ee3\u7801\u4e3apython\u8bed\u8a00\uff09\uff1a<\/p>\n<p><br \/>\u83b7\u53d6\u6587\u672c\u5bf9\u8c61\u672c\u8eab\u7a7a\u683c\u95f4\u8ddd\uff1a<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-af440db elementor-widget elementor-widget-code-highlight\" data-id=\"af440db\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>\r\n\r\n\r\ntextState = textObject.GetTextState(page);\r\n# \u83b7\u53d6\u8bcd\u95f4\u8ddd\r\nwordSpace = textState.wordspace;\r\n# \u83b7\u53d6\u5f53\u524d\u5b57\u4f53\u7684\u7a7a\u683c\u539f\u59cb\u5bbd\u5ea6\r\nspaceWidth_original = textState.font.GetCharWidth(ord(' ')) \/ 1000;\r\n# \u6839\u636e\u8bcd\u95f4\u8dddspaceWidth_original\uff0c\u5b57\u4f53\u5927\u5c0ffont_size\uff0c\r\n#\u4ee5\u53ca\u6587\u672c\u7684\u6a2a\u5411\u7f29\u653eMatrix.a\u6bd4\u4f8b\uff0c \u8ba1\u7b97\u51fa\u5b9e\u9645PDF\u4e2d \u8be5\u6587\u672c\u5bf9\u8c61\u7684\u7a7a\u683c\u5b9e\u9645\u5bbd\u5ea6\r\nspaceWidth = 1 * spaceWidth_original * textState.font_size * textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>.GetMatrix().a + wordSpace\r\n\r\n\u8ba1\u7b97\u5355\u4e2a\u6587\u672c\u5bf9\u8c61\uff0c\u5b57\u7b26\u6240\u5360\u7684\u5de6\u53f3\u4e24\u4fa7\u7684\u5750\u6807\u3002\r\n\r\n\r\n#\u5de6\u4fa7\u5750\u6807\uff1a\r\ntextObj.GetCharPos(0).x;\r\n#\u53f3\u4fa7\u5750\u6807\uff1a\r\ntextObj.GetCharPos(textObj.GetCharCount()-1).x+textObj.GetCharWidthByIndex(textObj.GetCharCount()-1);\r\n\r\n\u5b8c\u6574\u4ee3\u7801\uff1a\r\n\r\n\r\ndef GetTextObjBoundary(textObj,is_left=True):\r\n    if is_left:\r\n        return textObj.GetCharPos(0).x;\r\n    else:\r\n        return textObj.GetCharPos(textObj.GetCharCount()-1).x+textObj.GetCharWidthByIndex(textObj.GetCharCount()-1);\r\n#textRow\u4e3a\u4e00\u884c\u5df2\u4ece\u5de6\u5f80\u53f3\u6392\u597d\u5e8f\u7684\u6587\u672c\u5bf9\u8c61\u6570\u7ec4\u3002\r\ndef GetTextInRow(textRow, page):\r\n    str=\"\"\r\n    prePosX=0;\r\n    textRow = sorted(textRow, key=lambda x: x.GetRect().left, reverse=False);\r\n    for i in range(0, len(textRow)):\r\n        textStr=textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>.GetText();\r\n        rect=textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>.GetRect()\r\n        textObj=textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>\r\n        if i==0:\r\n            str=textStr;\r\n            prePosX = GetTextObjBoundary(textObj,False);\r\n            continue;\r\n        distance=GetTextObjBoundary(textObj,True)-prePosX\r\n        GetTextObjBoundary(textObj,True);\r\n\r\n        textState = (textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>.GetTextState(page));\r\n        # \u83b7\u53d6\u8bcd\u95f4\u8ddd\r\n        wordSpace = textState.wordspace;\r\n        # \u83b7\u53d6\u5f53\u524d\u5b57\u4f53\u7684\u7a7a\u683c\u539f\u59cb\u5bbd\u5ea6\r\n        spaceWidth_original = textState.font.GetCharWidth(ord(' ')) \/ 1000;\r\n        # \u6839\u636e\u8bcd\u95f4\u8dddspaceWidth_original\uff0c\u5b57\u4f53\u5927\u5c0ffont_size\uff0c\u6587\u672c\u7684\u6a2a\u5411\u7f29\u653eMatrix.a\r\n        # \u8ba1\u7b97\u51fa\u5b9e\u9645PDF\u4e2d \u8be5\u6587\u672c\u5bf9\u8c61\u7684\u7a7a\u683c\u5bbd\u5ea6\r\n        spaceWidth = 1 * spaceWidth_original * textState.font_size * textRow<a href=\"https:\/\/support.fuxinsoft.cn\/?cat=38\" rel=\"tag\">\u798f\u6615PDF SDK \u8f6f\u4ef6\u5f00\u53d1\u5de5\u5177\u5305<\/a> &gt; <a href=\"https:\/\/support.fuxinsoft.cn\/?cat=77\" rel=\"tag\">\u798f\u6615PDF SDK(\u684c\u9762\/\u670d\u52a1\u5668)<\/a>.GetMatrix().a + wordSpace\r\n        #\u6839\u636e\u76f8\u90bb\u6587\u672c\u7684\u95f4\u8ddd\uff0c\u6765\u8ba1\u7b97\u7a7a\u683c\u7b26\u7684\u4e2a\u6570\r\n        spaceCount=(int)(distance\/spaceWidth+0.5)\r\n        for space in range(0,spaceCount):\r\n            str=str+\" \"\r\n        str=str+textStr;\r\n        prePosX = GetTextObjBoundary(textObj,False);\r\n    return str;<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>PDF\u9875\u9762\u4e0a\u4eba\u773c\u770b\u89c1\u7684\u4e00\u884c\u6587\u672c\uff0c\u53ef\u80fd\u662f\u7531\u591a\u4e2a\u72ec\u7acb\u7684\u6587\u672c\u5bf9\u8c61TextObject\u6784\u6210\uff0c \u5982\u679c\u9700\u8981\u81ea\u884c\u5c06\u6587\u672c\u5bfc\u51fa\uff0c [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-3167","post","type-post","status-publish","format-standard","hentry","category-gsdk"],"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\/3167","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\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3167"}],"version-history":[{"count":16,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/3167\/revisions"}],"predecessor-version":[{"id":7271,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/3167\/revisions\/7271"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}