How to add text to an xform

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
prasantha
User
Posts: 43
Joined: Fri Jun 24, 2022 8:15 am

How to add text to an xform

Post by prasantha »

Hi
I tried to add text inside a xform .
I could add an xfrom programatically, but i could not find a way to set a text inside a xform
I found below methods to do that. but i could not find any resource illustrate howt o use these methods.

IPXC_ContentItem.

void Text_SetData(ref byte pCIDs, [ComAliasName("PDFXEdit.ULONG_T")] uint nSize, IPXC_TState pNewTextState, out PXC_PointF stOffset);
void Text_SetData2(IPXS_PDFVariant pTJ, IPXC_TState pNewTextState, out PXC_PointF stOffset);
void Text_SetDataSA(Array pCIDs, IPXC_TState pNewTextState, out PXC_PointF stOffset);

So can any one provide me any resource shows how to use these methods. or can somebody let me know how to use this sample inputs.

Thank you
Prasantha
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to add text to an xform

Post by Vasyl-Tracker Dev Team »

Hi Prasantha.

You may use the following way:

Code: Select all

IPXC_Document doc;
...
IPXC_ContentCreator cc = doc.CreateContentCreator();

IPXC_Font fnt =  doc.CreateNewFont("Arial", PXC_CreateFontFlags.CreateFont_Italic, 600); // heavy italic
cc.SetFont(fnt);
cc.SetFontSize(12.0); // 12 pt
cc.SetFillColor(RGB(255,0,0));
cc.SetTextRenderMode(PXC_TextRenderingMode.TRM_Fill);

cc.ShowTextLine(0, 0, "Sample Text!",  -1, PXC_ShowTextLineFlags.STLF_Top);

IPXC_Content con = cc.Detach();

PXC_Rect cbbox;
cbbox.left = cbbox.top = 0;
cbbox.right = 100;
cbbox.bottom = -20;
con.BBox = cbbox;

IPXC_XForm xf;
...

xf.SetContent(con);
HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
prasantha
User
Posts: 43
Joined: Fri Jun 24, 2022 8:15 am

Re: How to add text to an xform

Post by prasantha »

Hi Vasyl Yaremyn,

THank you for your quick response. I could add an xform to the page. But the text i added does not shows. If I open it in editor and selected the text and changing any of the eproperty of the added text will make it visible. till that it is not visible.
Can you let me know whats missing in below code please.

IPXC_Page Page = Doc.Pages[pageNumber];
IPXC_Content content =Page.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone);
IPXC_ContentCreator cc = Doc.CreateContentCreator();
PXC_Rect rc;
rc.left = 100;
rc.right = 500;
rc.top = 500;
rc.bottom = 200;
cc.StartContainer("test");

PDFXEdit.IPXC_Font fnt = Doc.CreateNewFont2("ArialMT");


IPXC_XForm xForm = dOC.CreateNewXForm(rc);
IPXC_ContentCreator cc1 = Doc.CreateContentCreator();
cc1.SetFont(fnt);
cc1.SetFontSize(14.0f);
var auxInst = (IAUX_Inst)_Inst.GetExtension("AUX");
PDFXEdit.IColor color1 = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
color1.SetRGB(0.0f, 1.0f, 0.0f);
cc1.SetFillColorRGB(color1.RGB);
color1.SetRGB(0.0f, 1.0f, 0.0f);
cc1.ShowTextLine(100, 100, "Sample Text!", -1, (uint)PXC_ShowTextLineFlags.STLF_Top);
IPXC_Content xfromContent = cc1.Detach();
cc.PlaceXForm(xForm,"");
xForm.SetContent(xfromContent);
cc1.RestoreState();
cc.EndContainer();

IPXC_Content ccs = cc.Detach();
int nID1 = _Inst.Str2ID("op.addContent", false);
IOperation Op1 = _Inst.CreateOp(nID1);
ICabNode inpu1t1 = Op1.Params.Root["Input"];
inpu1t1.Add().v = dOC;
ICabNode options1 = Op1.Params.Root["Options"];
options1["Content"].v = ccs;
options1["TargetPage"].v = 0;


Op1.Do();
cc.RestoreState();
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to add text to an xform

Post by Vasyl-Tracker Dev Team »

The working example is here:

Code: Select all

PDFXEdit.IPXC_Document doc = pdfCtl.Doc.CoreDoc;
PDFXEdit.IPXC_ContentCreator cc = doc.CreateContentCreator();

IPXC_Font fnt = doc.CreateNewFont("Arial", (int)PXC_CreateFontFlags.CreateFont_Italic, 600); // heavy italic
cc.SetFont(fnt);
cc.SetFontSize(12.0); // 12 pt
PDFXEdit.IColor clrText = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
clrText.SetRGB(0.0f, 1.0f, 0.0f);
cc.SetFillColorRGB(clrText.RGB);
cc.SetTextRenderMode(PXC_TextRenderingMode.TRM_Fill);

cc.ShowTextLine(0, 0, "Sample Text!", -1, (int)PXC_ShowTextLineFlags.STLF_Top);

IPXC_Content con = cc.Detach();

PXC_Rect cbbox;
cbbox.left = cbbox.top = 0;
cbbox.right = 100;
cbbox.bottom = -20;
con.set_BBox(cbbox);

IPXC_XForm xf = doc.CreateNewXForm(cbbox);

xf.SetContent(con);

IPXC_Page pg = doc.Pages[0];
IPXC_Content pgCon = pg.GetContent(PXC_ContentAccessMode.CAccessMode_FullClone);

PDFXEdit.IPXC_ContentCreator pgCC = doc.CreateContentCreator();
pgCC.Attach(pgCon);

PXC_Rect xfbox = cbbox;

// set xform's position on the page
double newLeft = 200;
double newTop = 500;
double DX = -xfbox.left + newLeft;
double DY = -xfbox.top + newTop;
xfbox.left += DX; xfbox.right += DX;
xfbox.top += DY; xfbox.bottom += DY;

pgCC.PlaceXFormEx(xf, xfbox, "textXF");

pgCon = pgCC.Detach();

IOperation op = pdfCtl.Inst.CreateOp(pdfCtl.Inst.Str2ID("op.replaceContent"));
ICabNode inp = op.Params.Root["Input"];
inp.Add().v = doc;
ICabNode opt = op.Params.Root["Options"];
opt["NewContent"].v = pgCon;
opt["TargetPage"].v = 0;

op.Do();
HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.