{"id":1895,"date":"2024-07-24T16:48:05","date_gmt":"2024-07-24T08:48:05","guid":{"rendered":"https:\/\/support.foxitsoftware.cn\/?p=1895"},"modified":"2024-09-05T15:05:53","modified_gmt":"2024-09-05T07:05:53","slug":"%e3%80%90plugin-sdk%e3%80%91%e5%a6%82%e4%bd%95%e4%b8%ba%e5%a4%9a%e4%b8%aapdf%e9%a1%b5%e9%9d%a2%e5%90%8c%e6%97%b6%e6%b7%bb%e5%8a%a0%e6%b3%a8%e9%87%8a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=1895","title":{"rendered":"\u5982\u4f55\u4e3a\u591a\u4e2aPDF\u9875\u9762\u540c\u65f6\u6dfb\u52a0\u6ce8\u91ca\uff1f"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">\u5982\u679c\u60a8\u9700\u8981\u4e3a\u4e00\u4e2a\u5728\u7f16\u8f91\u5668\u4e0a\u5df2\u7ecf\u6253\u5f00\u7684PDF\u7684\u591a\u4e2a\u9875\u9762\u6dfb\u52a0\u6ce8\u91ca\uff0c \u9700\u8981\u6ce8\u610f\u7684\u4e8b\uff0c\u5f00\u53d1\u5305\u793a\u4f8b\u4e2d\u7684\u63a5\u53e3\u4e3aFRPageViewAddAnnot()\uff0c\u53ea\u80fd\u5bf9\u5df2\u52a0\u8f7d\u8fc7\u89c6\u56fe\u7684(\u7528\u6237\u6d4f\u89c8\u8fc7\u7684)\u9875\u9762\u6dfb\u52a0\u6ce8\u91ca\u3002\u5982\u679c\u8981\u5bf9\u8fd8\u672a\u52a0\u8f7d\u7684\u9875\u9762\u6dfb\u52a0\u6ce8\u91ca\uff0c\u53ef\u4ee5\u4f7f\u7528FRDocAddAnnot()\u63a5\u53e3\u6dfb\u52a0\u6ce8\u91ca\u3002<\/p>\n\n\n\n<p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-body-font-family has-medium-font-size\"><code>void CreateAnnot()<br>{<br>\tFS_FloatPoint pointLeftTop, pointRightBottom;<br>\tpointLeftTop.m_PointX = 100;<br>\tpointRightBottom.m_PointX = 400;<br>\tpointLeftTop.m_PointY = 200;<br>\tpointRightBottom.m_PointY=100;<br><br>\tFR_Document frDocument = FRAppGetActiveDocOfPDDoc();<br>\tFPD_Document fpdDocument = FRDocGetPDDoc(frDocument);<br>\tFR_DocView frDocView = FRDocGetCurrentDocView(frDocument);<br>\tFR_PageView frPageView = FRDocViewGetCurrentPageView(frDocView);<br><br>\tfor (int i = 0; i &lt; FPDDocGetPageCount(fpdDocument); i++)<br>\t{<br>\t\tFS_FloatRect rectFirst;<br>\t\trectFirst.left = pointLeftTop.m_PointX;<br>\t\trectFirst.right = pointRightBottom.m_PointX;;<br>\t\trectFirst.bottom = pointRightBottom.m_PointY;<br>\t\trectFirst.top = pointLeftTop.m_PointY;<br>\t\tFR_Annot frAnnot = FRDocAddAnnot(frDocument, i, \"Stamp\", rectFirst);<br>\t\tFPD_Annot  fpdAnnot = FRAnnotGetPDFAnnot(frAnnot);<br><br>\t\tFR_Page frPage = FRDocGetPage(frDocument, i);<br><br>\t\tFPD_Page fpdPage = FPDPageNew();<br><br>\t\tFPD_Object pPageDict = FPDDocGetPage(fpdDocument, i);<br>\t\tFPDPageLoad(fpdPage, fpdDocument, pPageDict, TRUE);<br><br>\t\tFPD_Object fpdObject =<br>\t\t\tFPDAnnotGetAnnotDict(fpdAnnot);\/\/ FPDDictionaryNew();<br>\t\t\/\/set subtype of the annot<br>\t\tFPD_Object fpdfstringAnnot = FPDNameNew(\"Annot\");<br>\t\tFPDDictionaryAddValue(fpdObject, \"Type\", fpdfstringAnnot);<br>\t\tFPDDictionaryAddValue(fpdObject, \"Subtype\", FPDNameNew(\"Stamp\"));<br>\t\tFPDDictionaryAddValue(fpdObject, \"Subj\", FPDStringNew(FSByteStringNew3(\"Stamp\", -1), 0));<br><br><br>\t\t\/\/set quadpoints of the annot<br>\t\tFPD_Object quad = FPDArrayNew(); \/\/{x1, y1, x2, y2, x3, y3, x4, y5}<br>\t\tFPDArrayAddNumber(quad, rectFirst.left); \/\/x1<br>\t\tFPDArrayAddNumber(quad, rectFirst.top);\/\/y1<br>\t\tFPDArrayAddNumber(quad, rectFirst.right);\/\/x2<br>\t\tFPDArrayAddNumber(quad, rectFirst.top);\/\/y2<br>\t\tFPDArrayAddNumber(quad, rectFirst.left);\/\/x3<br>\t\tFPDArrayAddNumber(quad, rectFirst.bottom);\/\/y3<br>\t\tFPDArrayAddNumber(quad, rectFirst.right);\/\/x4<br>\t\tFPDArrayAddNumber(quad, rectFirst.bottom);\/\/y4<br>\t\tFPDDictionaryAddValue(fpdObject, \"QuadPoints\", quad);<br>\t\tFPDDictionaryAddValue(fpdObject, \"NM\", FPDNameNew(\"TextName\"));<br><br>\t\tFPDDictionaryAddValue(fpdObject, \"T\", FPDNameNew(\"AuthorTest\"));<br><br>\t\tFPD_Object quadColor = FPDArrayNew();<br>\t\tFS_COLORREF color = RGB(255, 215, 0);<br>\t\t\/\/set color of the annot<br>\t\tFPDArrayAddNumber(quadColor, (FS_FLOAT)GetRValue(color) \/ 255.0f); \/\/1 means RGB Color<br>\t\tFPDArrayAddNumber(quadColor, (FS_FLOAT)GetGValue(color) \/ 255.0f); \/\/Defines the color<br>\t\tFPDArrayAddNumber(quadColor, (FS_FLOAT)GetBValue(color) \/ 255.0f); \/\/Defines the color<br>\t\tFPDDictionaryAddValue(fpdObject, \"C\", quadColor);<br><br>\t\tFS_LPCWSTR ws = (FS_LPCWSTR)L\"This is initial text\";<br>\t\tFPD_Object fpdfstringPopout = FPDStringNewW(ws);<br>\t\t\/\/set comment info of the annot<br>\t\tFPDDictionaryAddValue(fpdObject, \"Contents\", fpdfstringPopout);<br>\t\t\/\/set BBox of the annot<br>\t\tFPDDictionarySetAtRect(fpdObject, \"Rect\", rectFirst);<br>\t\tauto pAPDict = FPDDictionaryGetDict(fpdObject, \"AP\");<br>\t\tif (pAPDict == nullptr)<br>\t\t{<br>\t\t\tpAPDict = FPDDictionarySetNewAt(fpdObject, \"AP\", FPD_OBJ_DICTIONARY);<br>\t\t}<br>\t\tFS_DWORD dwApObjNum = 0;<br>\t\tFS_DIBitmap pBitmap = FSDIBitmapLoadFromPNGIcon(L\"D:\\\\test\\\\thumbnail_image001.png\");<br>\t\tFPD_Object pObj = CreateAppearanceDict(fpdDocument, pBitmap, 0, &amp;dwApObjNum);<br>\t\tFPDDictionarySetAtReferenceToDoc(pAPDict, \"N\", fpdDocument, dwApObjNum);<br>\t\tFPDDictionaryAddValue(fpdObject, \"AP\", pAPDict);<br><br>\t\t\/\/\u5c06\u65b0\u589e\u6ce8\u91ca\u6dfb\u52a0\u5230\u4fa7\u8fb9\u680f\u7684\u6ce8\u91ca\u5217\u8868\u4e2d<br>\t\tif (frAnnot != NULL)<br>\t\t{<br>\t\t\tFR_MarkupPanel panel = FRMarkupPanelGetMarkupPanel();<br>\t\t\tif (panel)<br>\t\t\t{<br>\t\t\t\tFRMarkupPanelAddAnnot(panel, frAnnot, TRUE, TRUE);<br>\t\t\t}<br>\t\t}<br>\t}<br>\t\/\/\u5237\u65b0\u5f53\u524d\u9875\u9762\uff0c\u8ba9\u6ce8\u91ca\u663e\u793a<br>\tFRDocReloadPage(frDocument, FRPageViewGetPageIndex(FRDocViewGetCurrentPageView(frDocView)), FALSE);<br>}<br><br><\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u8fd9\u4e2a\u793a\u4f8b\u662f\u6dfb\u52a0\u7684&#8221;\u56fe\u7ae0&#8221;\u6ce8\u91ca\uff0c\u6240\u4ee5\u4f1a\u7528\u5230\u3002\u5982\u679c\u662f\u5176\u4ed6\u7c7b\u578b\u6ce8\u91ca\u4f8b\u5982&#8221;\u9ad8\u4eae&#8221;\u4e0d\u4e00\u5b9a\u9700\u8981\u4e0b\u9762\u7684\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u6dfb\u52a0\u6ce8\u91ca\u5916\u89c2\nFPD_Object CreateAppearanceDict(FPD_Document pdfDoc, FS_DIBitmap bitmap, int nRotate, FS_DWORD* pObjNum)\n{\n\tif (!pdfDoc || !bitmap)\n\t\treturn nullptr;\n\tFS_DWORD dwNewObjNumber = 0;\n\tFPD_Object apperenceDict = FPDDictionaryNew();\n\n\tFS_AffineMatrix streamMatrix;\n\tswitch (nRotate)\n\t{\n\tcase 0:\n\t{\n\t\tstreamMatrix.a = 1.0f;\n\t\tstreamMatrix.b = 0.0f;\n\t\tstreamMatrix.c = 0.0f;\n\t\tstreamMatrix.d = 1.0f;\n\t}\n\tbreak;\n\tcase 90:\n\t{\n\t\tstreamMatrix.a = 0.0f;\n\t\tstreamMatrix.b = 1.0f;\n\t\tstreamMatrix.c = -1.0f;\n\t\tstreamMatrix.d = 0.0f;\n\t}\n\tbreak;\n\tcase 180:\n\t{\n\t\tstreamMatrix.a = -1.0f;\n\t\tstreamMatrix.b = 0.0f;\n\t\tstreamMatrix.c = 0.0f;\n\t\tstreamMatrix.d = -1.0f;\n\t}\n\tbreak;\n\tcase 270:\n\t{\n\t\tstreamMatrix.a = 0.0f;\n\t\tstreamMatrix.b = -1.0f;\n\t\tstreamMatrix.c = 1.0f;\n\t\tstreamMatrix.d = 0.0f;\n\t}\n\tbreak;\n\tdefault:\n\t\tbreak;\n\t}\n\tstreamMatrix.e = 0;\n\tstreamMatrix.f = 0;\n\tFPDDictionarySetAtMatrix(apperenceDict, \"Matrix\", streamMatrix);\n\tFPD_Object resourcesDict = FPDDictionaryNew();\n\tFPD_Object xObject = FPDDictionaryNew();\n\n\tFPD_Image image = FPDImageNew(pdfDoc);\n\t\/\/ON_SCOPE_EXIT(&#091;&amp;] {\n\n\t\/\/});\n\tFPDImageSetImage(image, bitmap, FALSE, nullptr);\n\tFPD_Object imgStream = FPDImageGetStream(image);\n\tif (imgStream)\n\t{\n\t\tdwNewObjNumber = FPDDocAddIndirectObject(pdfDoc, imgStream);\n\t\tFPDDictionarySetAtReferenceToDoc(xObject, \"ImgSignature\", pdfDoc, dwNewObjNumber);\n\t}\n\tFPDDictionarySetAt(resourcesDict, \"XObject\", xObject, nullptr);\n\n\tFPD_Object extGStateDict = FPDDictionaryNew();\n\tFPDDictionarySetAtNumber(extGStateDict, \"CA\", 1);\n\tFPDDictionarySetAtNumber(extGStateDict, \"ca\", 1);\n\tFS_DWORD dwNewExtGStateObjNumber = FPDDocAddIndirectObject(pdfDoc, extGStateDict);\n\tFPD_Object extGStateDictRef = FPDDictionaryNew();\n\tFPDDictionarySetAtReferenceToDoc(extGStateDictRef, \"FXE1\", pdfDoc, dwNewExtGStateObjNumber);\n\tFPDDictionarySetAt(resourcesDict, \"ExtGState\", extGStateDictRef, nullptr);\n\n\tFPDDictionarySetAt(apperenceDict, \"Resources\", resourcesDict, nullptr);\n\n\tint bmpWidth = FSDIBitmapGetWidth(bitmap);\n\tint bmpHeight = FSDIBitmapGetHeight(bitmap);\n\n\tFPD_Object streamBBox = FPDArrayNew();\n\tFPDArrayAddNumber(streamBBox, 0);\n\tFPDArrayAddNumber(streamBBox, 0);\n\tFPDArrayAddNumber(streamBBox, bmpWidth);\n\tFPDArrayAddNumber(streamBBox, bmpHeight);\n\n\n\tFPDDictionarySetAt(apperenceDict, \"BBox\", streamBBox, nullptr);\n\tFPDDictionarySetAtName(apperenceDict, \"Type\", \"XObject\");\n\tFPDDictionarySetAtName(apperenceDict, \"Subtype\", \"Form\");\n\n\tFS_ByteString apStreamData = FSByteStringNew();\n\n\tFSByteStringFormat(apStreamData, \"q\\n\/FXE1 gs\\n%d 0 0 %d 0 0 cm\\n\/ImgSignature Do\\nQ\", bmpWidth, bmpHeight);\n\n\tauto pNewContents = FPDStreamNew();\n\tFPDStreamInitStream(pNewContents, NULL, 0, apperenceDict);\n\tFPDStreamSetData(pNewContents, (FS_LPBYTE)FSByteStringCastToLPCBYTE(apStreamData),\n\t\tFSByteStringGetLength(apStreamData), FALSE, FALSE);\n\tauto dwObjNum = FPDDocAddIndirectObject(pdfDoc, pNewContents);\n\tif (pObjNum)\n\t\t*pObjNum = dwObjNum;\n\n\tFSByteStringDestroy(apStreamData);\n\tFPDImageDestroy(image);\n\treturn pNewContents;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"647\" height=\"777\" src=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2024\/07\/image-19.png\" alt=\"\" class=\"wp-image-1898\" srcset=\"https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2024\/07\/image-19.png 647w, https:\/\/support.fuxinsoft.cn\/wp-content\/uploads\/2024\/07\/image-19-250x300.png 250w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u60a8\u9700\u8981\u4e3a\u4e00\u4e2a\u5728\u7f16\u8f91\u5668\u4e0a\u5df2\u7ecf\u6253\u5f00\u7684PDF\u7684\u591a\u4e2a\u9875\u9762\u6dfb\u52a0\u6ce8\u91ca\uff0c \u9700\u8981\u6ce8\u610f\u7684\u4e8b\uff0c\u5f00\u53d1\u5305\u793a\u4f8b\u4e2d\u7684\u63a5\u53e3\u4e3aFRPage [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[],"class_list":["post-1895","post","type-post","status-publish","format-standard","hentry","category-plugin-sdk"],"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\/1895","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=1895"}],"version-history":[{"count":6,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/1895\/revisions"}],"predecessor-version":[{"id":2738,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/1895\/revisions\/2738"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}