op.annots.addNew

From PDF XChange PDF SDK
Jump to: navigation, search


Overview

The operation forms undo/redo data, sends correspondent events and modifies the document when the annotations were added on the Core level.

Parameters

Name Type Description
Input Array Array of IUnknown-based objects containing the IPXC_Annotation objects that were inserted to the document on the Core level. Note that all of the annotations must belong to one document.
Output Array Array of IUnknown-based objects containing the IPXC_Document to which the annotations were added.

Sample

//C#
private void AddSquareAnnotation(PDFXEdit.IPXV_Document pDoc, PDFXEdit.PXV_Inst pInst)
{
	if (pDoc == null)
		return;
	PDFXEdit.IPXC_Page pPage = pDoc.CoreDoc.Pages[0];
	PDFXEdit.PXC_Rect rc;
	rc.left = 50;
	rc.right = 100;
	rc.top = 50;
	rc.bottom = 100;
	PDFXEdit.IPXS_Inst pSInt = (PDFXEdit.IPXS_Inst)pInst.GetExtension("PXS");
	//Inserting square annotation as example
	uint nSquare = pSInt.StrToAtom("Square");
	PDFXEdit.IPXC_Annotation pAnnot = pPage.InsertNewAnnot(nSquare, ref rc, 0);
	if (pAnnot == null)
		return;

	//Modifying annotation data so that we will have dashed lines of chosen color with given opacity
	PDFXEdit.IPXC_AnnotData_SquareCircle SQData = (PDFXEdit.IPXC_AnnotData_SquareCircle)pAnnot.Data;
	SQData.Opacity = 0.7;
	var color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
	color.SetRGB(0.0f, 1.0f, 1.0f);
	SQData.Color = color;
	var border = new PDFXEdit.PXC_AnnotBorder();
	border.nStyle = PDFXEdit.PXC_AnnotBorderStyle.ABS_Dashed;
	border.nWidth = 4.0f;
	border.DashArray = new float[10];
	border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes
	border.nDashCount = 2; //Number of dashes
	SQData.set_Border(border);
	pAnnot.Data = SQData;

	//Creating the operation that will send the event that the annotation was added to all of the listeners
	int nID = pInst.Str2ID("op.annots.addNew", false);
	PDFXEdit.IOperation pOp = pInst.CreateOp(nID);
	PDFXEdit.ICabNode input = pOp.Params.Root["Input"];
	input.Add().v = pAnnot;
	pOp.Do();
}