IPXC_Page::InsertNewAnnot Method

From PDF XChange PDF SDK
Revision as of 23:49, 21 April 2016 by Palamar (Talk | contribs)

Jump to: navigation, search


Inserts new annotation with given type into the given position with given Z-order.

Syntax

HRESULT InsertNewAnnot([in]                               ULONG              nAnnotType,
                       [in]                               PXC_Rect*          stLocation,
                       [in, defaultvalue(-1)]             ULONG              nPos,
                       [out, retval, defaultvalue(NULL)]  IPXC_Annotation**  pAnnot);

Parameters

nAnnotType
[in] Type of annotation that will be inserted.
stLocation
[in] Pointer to PXC_Rect containing the coordinates of the inserted annotation.
nPos
[in, defaultvalue(-1)] Position in annotation's Z-order on page. By default the inserted annotation will appear on top of the other annotations on the page.
pAnnot
[out, retval, defaultvalue(NULL)] Pointer to IPXC_Annotation containing the resulting annotation.

Return Value

Returns S_OK if operation was successful or error code in other cases.

Sample

//C#
public int HitTestPage(PDFXEdit._POINTL pt, out PDFXEdit.PXC_Point ptPagePoint)
{
	//Converting input data into given structures
	PDFXEdit.tagPOINT ptIn = new PDFXEdit.tagPOINT();
	ptIn.x = pt.x;
	ptIn.y = pt.y;
	PDFXEdit.tagPOINT ptRes = new PDFXEdit.tagPOINT();
	//Converting screen point to PDFXEdit client point
	pdfCtl.Doc.ActiveView.PagesView.Obj.ScreenPtToClient(ptIn, out ptRes);
	//And then checking whether it is on page and returning it in page coordinate system if so
	return pdfCtl.Doc.ActiveView.PagesView.Layout.HitTest(ptRes, out ptPagePoint);
}
//Adding annotation from given string in the given screen coordinate
public bool AddAnnotFromText(PDFXEdit._POINTL pt, string str)
{
	PDFXEdit.PXC_Point ptPagePoint = new PDFXEdit.PXC_Point();
	//Checking whether the point is on one of the document's pages
	int nResPageNum = HitTestPage(pt, out ptPagePoint);
	if (nResPageNum < 0)
		return false;
	//Creating rectangle for the new Free Text annotation
	PDFXEdit.PXC_Rect rc;
	rc.left = ptPagePoint.x;
	rc.right = ptPagePoint.x + 200;
	rc.top = ptPagePoint.y - 200;
	rc.bottom = ptPagePoint.y;
	PDFXEdit.IPXS_Inst pSInt = (PDFXEdit.IPXS_Inst)pdfCtl.Inst.GetExtension("PXS");
	//Getting Free Text annotation atom for the InsertNewAnnot method
	uint nTextBox = pSInt.StrToAtom("FreeText");
	PDFXEdit.IPXC_Page pPage = pdfCtl.Doc.CoreDoc.Pages[(uint)nResPageNum];
	PDFXEdit.IPXC_Annotation pAnnot = pPage.InsertNewAnnot(nTextBox, ref rc, 0);
	if (pAnnot == null)
		return false;
	//Filling the annotation with needed text
	PDFXEdit.IPXC_AnnotData_FreeText FTData = (PDFXEdit.IPXC_AnnotData_FreeText)pAnnot.Data;
	FTData.Contents = str;
	pAnnot.Data = FTData;
	//Executing the operation so that the annotation will be updated from structure
	int nID = pdfCtl.Inst.Str2ID("op.annots.addNew", false);
	PDFXEdit.IOperation pOp = pdfCtl.Inst.CreateOp(nID);
	PDFXEdit.ICabNode input = pOp.Params.Root["Input"];
	input.Add().v = pAnnot;
	pOp.Do();

	return true;
}

See Also

IPXC_Page