Insert RichText (RTF) in FreeText Annot

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.
Post Reply
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Insert RichText (RTF) in FreeText Annot

Post by espens »

Copy & paste from WordPad into a FreeText / Text Box annot works through the UI and I want to do the same from code.

Playing with the sample found in IPXC_Page::InsertNewAnnot I can easily insert plain text, but trying to set an RTF string ({rtf1\ansi...) using the RichContent of the IPXC_AnnotData_FreeText doesn't do much.

Any suggestions?
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Insert RichText (RTF) in FreeText Annot

Post by Vasyl-Tracker Dev Team »

Currently you cannot just put the RTF-text directly to the RichContent. Its required to convert it to the XFA Rich Text Format before (XML based format).
Probably in the future we will add feature for converting from RTF to XFA RTF..
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.
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Re: Insert RichText (RTF) in FreeText Annot

Post by espens »

Would it be possible to put the RTF in the clipboard and then invoke a paste command, as it is working through the UI.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Insert RichText (RTF) in FreeText Annot

Post by Vasyl-Tracker Dev Team »

Technically - yes. But you must have activated TextEditor control in UI for corresponding text-annotation before executing the Paste command.
I'm not sure that it is what you want..
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.
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Re: Insert RichText (RTF) in FreeText Annot

Post by espens »

It's basically what I want. Which brings up another question.

I want the user to place a Text Box on the Page though the UI and as it's placed on the page and before the user starts typing I want to inject a default string (In Rich Format). Looking at the events i see that e.annots.inserted is raised as the text box looses focus after it is inserted. This is too late as the user would then have started typing. I do not want to inject my text into just any text box as the editor gets actived (e.document.textEditor.started) but only when the textbox is a new text box.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Insert RichText (RTF) in FreeText Annot

Post by Vasyl-Tracker Dev Team »

Hi, Espens.

We will improve some moments with text-editor notifications by providing additional info with such events.
Also we'll provide detailed information about this improvement a bit later, please wait..

Cheers.
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.
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Re: Insert RichText (RTF) in FreeText Annot

Post by espens »

Any updates to text box events?

I'm trying to add a feature that inserts a custom text into a textbox when a text box is placed on a page.

Would also want to see this for form fields.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Insert RichText (RTF) in FreeText Annot

Post by Tracker Supp-Stefan »

Hello espens,

I checked with a colleague from the European dev office, but they say that this will need Vasyl's attention, and he is in Canada, so I will ask him to post an update as soon as he can!

Regards,
Stefan
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Insert RichText (RTF) in FreeText Annot

Post by Vasyl-Tracker Dev Team »

Hi Espens.
Any updates to text box events?
Sorry for delay with that. In next couple days we will add new features that will provide full access to our text-edit control.
When it is ready (should be by next week) - we will notify you and you will be able to try it using our technical builds.

Cheers.
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.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Insert RichText (RTF) in FreeText Annot

Post by Sasha - Tracker Dev Team »

Hello espens,

We've updated the code. Now you can change the TextBox text when inserting by using this code:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_document_textEditor_started])
{
	IntPtr outPtr = new IntPtr(e.pEvent.Param1);
	PDFXEdit.IPXV_TextEditor tEdit = (PDFXEdit.IPXV_TextEditor)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(outPtr);
	tEdit.EditCtl.AppendText("Test Text");
	//RichText
	//tEdit.EditCtl.SetRichText(); //This one uses IStream as an input - check out the IStreamWrapper in the FullDemo
You can do that by using the latest DevBuild available here:
https://forum.pdf-xchange.com/ ... 66&t=25943

Also, an example on how to get\set the RTF\XFA for the FreeText annotation:

Code: Select all

PDFXEdit.IOperation op = pdfCtl.Inst.CreateOp(pdfCtl.Inst.Str2ID("op.annot.setData"));
PDFXEdit.IPXC_Document cdoc = pdfCtl.Doc.CoreDoc;
PDFXEdit.IPXC_Page pg = cdoc.Pages[0];
uint cnt = pg.GetAnnotsCount();
for (uint i = 0; i < cnt; i++)
{
	PDFXEdit.IPXC_Annotation a = pg.GetAnnot(i);
	if (a.IsMarkup)
	{
		PDFXEdit.IPXC_AnnotData_Markup ad = (PDFXEdit.IPXC_AnnotData_Markup)a.Data;
		string rc = ad.RichContent;
		string rtf = pxcInst.ConvertRC2RTF(cdoc, rc, "", (int)PDFXEdit.PXC_ConvertRCFlags.PXC_ConvertRC_AnnotText);

		ad.RichContent = pxcInst.ConvertRTF2RC(cdoc, rtf, (int)PDFXEdit.PXC_ConvertRCFlags.PXC_ConvertRC_AnnotText);

		PDFXEdit.ICabNode pr = op.Params.Root;
		pr["Input"].Clear();
		pr["Input"].Add().v = a;
		pr["Options.NewData"].v = ad;

		op.Do(0);
	}
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Re: Insert RichText (RTF) in FreeText Annot

Post by espens »

Thank you.

This will work for us
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: Insert RichText (RTF) in FreeText Annot

Post by John - Tracker Supp »

Excellent :)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
Post Reply