IPXC_Page::InsertNewAnnot Method

From PDF XChange PDF SDK
Jump to: navigation, search
(Sample)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
__NOTOC__
 
[[Category:Editor]]
 
[[Category:Editor]]
 
{{#customTitle:IPXC_Page::InsertNewAnnot Method}}
 
{{#customTitle:IPXC_Page::InsertNewAnnot Method}}
{{#parentPage:PXV:IPXC_Page|InsertNewAnnot Method|method}}
+
{{#parentPage:PXV:IPXC_Page#Methods|InsertNewAnnot|method}}
 
{{ToReview}}
 
{{ToReview}}
  
Line 8: Line 9:
 
== Syntax ==
 
== Syntax ==
 
<pre class="brush:cpp;gutter:false">HRESULT InsertNewAnnot([in]                              ULONG              nAnnotType,
 
<pre class="brush:cpp;gutter:false">HRESULT InsertNewAnnot([in]                              ULONG              nAnnotType,
                       [in]                              PXC_Rect*          pLocation,
+
                       [in]                              PXC_Rect*          stLocation,
 
                       [in, defaultvalue(-1)]            ULONG              nPos,
 
                       [in, defaultvalue(-1)]            ULONG              nPos,
                       [out, retval, defaultvalue(NULL)]  IPXC_Annotation**  ppAnnot);</pre>
+
                       [out, retval, defaultvalue(NULL)]  IPXC_Annotation**  pAnnot);</pre>
  
 
== Parameters ==
 
== Parameters ==
 
;nAnnotType
 
;nAnnotType
:[in]  Type of annotation which will be inserted.
+
:[in]  Type of annotation that will be inserted.
;pLocation
+
;stLocation
 
:[in]  Pointer to [[PXV:PXC_Rect|PXC_Rect]] containing the coordinates of the inserted annotation.
 
:[in]  Pointer to [[PXV:PXC_Rect|PXC_Rect]] containing the coordinates of the inserted annotation.
 
;nPos
 
;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.
 
:[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.
;ppAnnot
+
;pAnnot
 
:[out, retval, defaultvalue(NULL)]  Pointer to [[PXV:IPXC_Annotation|IPXC_Annotation]] containing the resulting annotation.
 
:[out, retval, defaultvalue(NULL)]  Pointer to [[PXV:IPXC_Annotation|IPXC_Annotation]] containing the resulting annotation.
  
 
== Return Value ==
 
== Return Value ==
 
Returns S_OK if operation was successful or error code in other cases.
 
Returns S_OK if operation was successful or error code in other cases.
 +
 +
== Sample ==
 +
<pre class="brush:c#">//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;
 +
rc.bottom = ptPagePoint.y - 200;
 +
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;
 +
}
 +
</pre>
  
 
== See Also ==
 
== See Also ==
See also [[PXV:IPXC_Page|IPXC_Page]].
+
[[PXV:IPXC_Page|IPXC_Page]]

Latest revision as of 00:56, 25 April 2018


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;
	rc.bottom = ptPagePoint.y - 200;
	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