如何创建一个文档内的跳转链接?

如果需要在文档某个位置创建链接,用于快速跳转到文档内其他页面。可以通过创建Link注释,并为link增加文档内跳转动作文档实现。

示例代码如下:

void AddLink(FS_FloatRect rectLink, int  pageIndex, int gotoPageIndex)
{
	FR_Document frDoc = FRAppGetActiveDocOfPDDoc();
	FPD_Document fpdDoc = FRDocGetPDDoc(frDoc);
	FR_DocView frDocView = FRDocGetCurrentDocView(frDoc);
	FPD_Object pPageDict = (FPDDocGetPage(fpdDoc, pageIndex));
	FPD_Object annots = FPDDictionaryGetArray(pPageDict, "Annots");
	if (annots == NULL)
	{
		annots = FPDArrayNew();
		FPDDictionaryAddValue(pPageDict, "Annots", annots);
	}
	//跳转到下一页
	FPD_Object pPageDict_goto = (FPDDocGetPage(fpdDoc, gotoPageIndex));
	FPD_Page fpdPage_AddAnnot = FPDPageNew();
	FPDPageLoad(fpdPage_AddAnnot, fpdDoc, pPageDict, false);
	FPD_Object fpdObject = FPDDictionaryNew();
	//set subtype of the annot
	FS_ByteString strtype = FSByteStringNew3("Annot", -1);
	FPD_Object fpdfstringAnnot = FPDNameNew("Annot");//strtype);
	FPDDictionaryAddValue(fpdObject, "Type", fpdfstringAnnot);
	FS_ByteString strSubtype = FSByteStringNew3("Link", -1);
	FPD_Object fpdfstringSubtype = FPDNameNew("Link");//(strSubtype, 0);
	FPDDictionaryAddValue(fpdObject, "Subtype", fpdfstringSubtype);

	FPD_Object quad = FPDArrayNew(); //{x1, y1, x2, y2, x3, y3, x4, y5}
	FPDArrayAddNumber(quad, rectLink.left); //x1
	FPDArrayAddNumber(quad, rectLink.top);//y1
	FPDArrayAddNumber(quad, rectLink.right);//x2
	FPDArrayAddNumber(quad, rectLink.top);//y2
	FPDArrayAddNumber(quad, rectLink.left);//x3
	FPDArrayAddNumber(quad, rectLink.bottom);//y3
	FPDArrayAddNumber(quad, rectLink.right);//x4
	FPDArrayAddNumber(quad, rectLink.bottom);//y4
	FPDDictionaryAddValue(fpdObject, "QuadPoints", quad);
	FPDDictionarySetAtRect(fpdObject, "Rect", rectLink);
	string strName = "LinkName";
	FPDDictionaryAddValue(fpdObject, "NM", FPDStringNew(FSByteStringNew3(strName.c_str(), -1), FALSE));
	FPD_Object c_dict = FPDArrayNew();
	FPDArrayAddNumber(c_dict, 1);
	FPDArrayAddNumber(c_dict, 0);
	FPDArrayAddNumber(c_dict, 0);
	FPDDictionaryAddValue(fpdObject, "C", c_dict);
	FPD_Object bs_dict = FPDDictionaryNew();
	FPDDictionaryAddValue(fpdObject, "F", FPDNumberNewByInt(4));
	FPDDictionaryAddValue(fpdObject, "H", FPDNameNew("P"));
	FPDDictionaryAddValue(bs_dict, "W", FPDNumberNewByInt(0));
	FPDDictionaryAddValue(fpdObject, "BS", bs_dict);

	//给Link注释 添加跳转动作
	{
		FPD_Action ac_dict = FPDActionNew2(fpdDoc, FPD_ActionType::GoTo);
		FPD_Object dest = FPDArrayNew();
		FPDArrayAddReferenceToDoc(dest, fpdDoc, FPDObjectGetobjNum(pPageDict_goto));
		{
			FPDArrayAddName(dest, "XYZ");
			FPDArrayAddInteger(dest, 10);
			FPDArrayAddInteger(dest, 750);
			FPDArrayAddInteger(dest, 0);
			FPD_Dest dest_new = FPDDestNew(dest);
			FPDActionSetDest(ac_dict, dest_new);
		}
		int num = FPDDocAddIndirectObject(fpdDoc, FPDActionGetDict(ac_dict));
	
		FPDDictionaryAddReference(fpdObject, "A", fpdDoc, num);

		FPDDictionaryAddReference(fpdObject, "P", fpdDoc, FPDObjectGetobjNum(pPageDict));

	}
	int pos = FPDDocAddIndirectObject(fpdDoc, fpdObject);
	FPDArrayAddReferenceToDoc(annots, fpdDoc, pos);

	FRDocReloadPage(frDoc, pageIndex, false);

}

使用示例如下:

FS_FloatRect rect;
rect.left = 100.00;
rect.right = 300.00;
rect.top = 500.00;
rect.bottom = 450.00;
int pageIndex=0,gotoPageIndex = 2;
AddLink(rect, pageIndex, gotoPageIndex);

实现效果:会在页面中间创建一个可以点击的Link区域,点击后承接之前的缩放比例,跳转显示文档的第三页。