Page 1 of 1

Extract link annotation text, change text color

Posted: Mon Dec 02, 2019 11:57 pm
by zarkogajic
Hi support,

Say I have a Link annotation on a page. I can get its Rect (where it is on the page).

How do I get the text on the page inside that rect (if there is any, of course)?

Also, how can I change that text color (so in general set text properties inside a rect on a page)?



Re: Extract link annotation text, change text color

Posted: Tue Dec 03, 2019 8:48 am
by Sasha - Tracker Dev Team
Hello zarkogajic,

This should help:
viewtopic.php?f=66&t=32582&p=133499&hil ... xt#p133499


Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Tue Dec 03, 2019 9:21 am
by zarkogajic
Hi Alex,

ok, will try...

Once I have that text - how to change the color of it?



Re: Extract link annotation text, change text color

Posted: Tue Dec 03, 2019 10:19 am
by Sasha - Tracker Dev Team
Hello zarko,

This should do the trick:
https://sdkhelp.pdf-xchange.com/vi ... _CharColor
You should change the color for every symbol that is inside of your rectangle.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Tue Dec 03, 2019 11:07 am
by zarkogajic
Hi Alex,

Just to confirm: this is what I'm after - so can you let me know what coding are you internally using to get the text under the link (if more direct than steps below)?

image.png

Steps:

1. GetPage -> aPage
2. aPage ->getText (nil, true, pageText)
3. pageText -> GetLinesCount (lineCount)
4. for each line
4.1. getLineInfo (PXC_TextLineInfo tti)
5. Get line text using pageText.getChars(tti.FirstCharIndex, tti.charcount)

I would then need to get the CharRect of every char and "build" up the rectangle - and finally if the rectangle is inside annotation's rectangle - this is the text I'm after?

Is this what you are suggesting? No other method like ExtractPageText(fromGivenRectange)?

If so, can you please help with using HitTest of IPXC_PageText - as I think I should be able to locate the lineIndex directly by this and not need to iterate over all lines - however whatever I use for stPosOnPage point (and I've tried using annots rect corners) - the result is never the line index where the annotation is.

-žarko

Re: Extract link annotation text, change text color

Posted: Thu Dec 05, 2019 2:08 pm
by zarkogajic
Hi Alex,

I do not see how to change the color of a character. I can use Get_CharColor to get an IColor. I can even do IColor.SetRGB() - but this does not apply it to the character.

So, how to do it? And also when done, if there's a corresponding pxv document, do I need to send some notification or fire some event, or?


Re: Extract link annotation text, change text color

Posted: Wed Dec 11, 2019 4:23 pm
by zarkogajic
Hi support,

ping....


Re: Extract link annotation text, change text color

Posted: Thu Dec 12, 2019 3:43 pm
by Sasha - Tracker Dev Team
Hello zarko,

Just doubled checked this. Sadly, you cannot simply change the symbol color due to PDF specification. What you can do is change the color of the entire text Content Item. Basically, in your case, you will have to split the entire line to 3 content items and change the color of the middle one.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Thu Dec 12, 2019 3:54 pm
by zarkogajic
Alex,

Hm ..

I'm (basically) after this:

image.png
And then: character color changed:

image.png

This is still one content item (OR?) - but characters have different text color.


p.s.
Yes, I want to get the characters "under" a Link annotation (I know how as per this topic) and change the color ...

-žarko

Re: Extract link annotation text, change text color

Posted: Thu Dec 12, 2019 3:57 pm
by Sasha - Tracker Dev Team
Hello žarko,

That's the thing - you are entering the text edit mode that does precisely what I told you - you may see this as a unified text, but in reality - it's a combination of many content items with different properties.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Thu Dec 12, 2019 4:06 pm
by zarkogajic
Hi Alex,

Ok.

Basically, in your case, you will have to split the entire line to 3 content items and change the color of the middle one.

What methods would need to be used for this?


-žarko

Re: Extract link annotation text, change text color

Posted: Wed Dec 25, 2019 10:53 am
by Sasha - Tracker Dev Team
Hello žarko,

Well this task is really complex as this will require going inside of the content item, splitting it be the specification (including fonts and states) that will be meaning - creating new content items in the needed positions.
What exactly do you want to achieve with such a complex task?

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Fri Dec 27, 2019 10:04 am
by zarkogajic
Hi Alex,

Thanks.

I want to ensure link annotations are in blue text color (of course, if the annotation is "above" text).


Re: Extract link annotation text, change text color

Posted: Wed Jan 29, 2020 4:13 pm
by zarkogajic
Hi Alex,

Ping... :)


Re: Extract link annotation text, change text color

Posted: Mon Feb 03, 2020 9:47 am
by Sasha - Tracker Dev Team
Hello žarko,

First you should read a PDF specification on how the text content items are presented. The problem lies within the Font Encoding. There can be 1, 2 (that are typical) or any other number of bytes per symbol to know where your starting and ending symbols lie. Then you should look at the font's metrics (widths) to know where these symbols are located. This you can take from the render level as we have a matrix and a positioning of each symbol. But you will have to work with the placement of the resulting symbols. Then you will have to make another content item, remove the unneeded stuff from the original item and place the new content item in the place where you need this.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Mon Feb 03, 2020 10:24 am
by zarkogajic
Hi Alex,

So, this is why you do internally to have this (?):

image.png
image.png (37.42 KiB) Viewed 4497 times
?


Re: Extract link annotation text, change text color

Posted: Mon Feb 03, 2020 10:31 am
by Sasha - Tracker Dev Team
Hello žarko,

I'm not sure that I have understood your question.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Mon Feb 03, 2020 1:15 pm
by zarkogajic
Hi Alex,

I guess I'm asking for some code samples to do:
you will have to make another content item, remove the unneeded stuff from the original item and place the new content item in the place where you need this
:)


Re: Extract link annotation text, change text color

Posted: Mon Feb 03, 2020 1:48 pm
by Sasha - Tracker Dev Team
Hello žarko,

All of this should be done on the Structure level so basically you will have to create a new item Variant based on the Specification and fill it with all of the needed data. There is a sample on how to work with structure in the CoreAPIDemo application.
Then you will have to use the IPXC_ContentItem::Text_GetData2/IPXC_ContentItem::Text_SetData2 methods to modify the needed data in the content item.

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Sun Feb 09, 2020 1:26 pm
by zarkogajic
Hi Alex,

Sorry, but I'm not able to follow you here - I would need to see some actual code, so pretty please :)

To make it simpler, how to change the color of some selected text?

Say I have the "select text" tool activated and I select some text -> my button click -> text color changes.



-žarko

Re: Extract link annotation text, change text color

Posted: Wed Feb 26, 2020 8:35 am
by Sasha - Tracker Dev Team
Hi žarko,

We've updated a CoreAPIDemo application with the code sample that changes even text content items to the red color. You can check it out here on our git:
https://github.com/tracker-software/PDF ... Content.cs

Cheers,
Alex

Re: Extract link annotation text, change text color

Posted: Tue Jun 02, 2020 10:53 am
by zarkogajic
Hi Support,

I'm back to this "problem" I need to solve: change the text color of some selected text, more specifically change the text color of the text "under" a specific PXC_Rect (link annotation rectangle).

As discussed this would involve "breaking" of content items (IPXC_ContentItem / PXC_CIType.CIT_Text)...

Any chance for some code sample?

I know this is complex to be done from code, so I would be happy even with just: enter edit mode, somehow select text (while in edit mode: "edit text elements as block") by rectangle, change selection properties (font color), exit edit mode.

-žarko

Re: Extract link annotation text, change text color

Posted: Thu Jun 04, 2020 7:48 am
by Sasha - Tracker Dev Team
Hello zarkogajic,

If it were that easy - I would have suggested it earlier.
Here's what I have in my samples:

Code: Select all

private void SetContentColor(PDFXEdit.IPXV_Document Doc, PDFXEdit.PXV_Inst Inst)
{
	if (Doc == null)
		return;
	//Creating contentItems.setProps operation
	int nID = Inst.Str2ID("op.contentItems.setProps", false);
	PDFXEdit.IOperation pOp = Inst.CreateOp(nID);
	var input = pOp.Params.Root["Input"];
	input.Add().v = Doc.CoreDoc;
	PDFXEdit.ICabNode options = pOp.Params.Root["Options"];
	int nSelID = Inst.Str2ID("selection.contentItems", false);
	uint nPage = 0; //Page number that will have it's content items modified
					//First we need to create content items selection
					//PDFXEdit.IPXV_ContentItemsSelection itSel = (PDFXEdit.IPXV_ContentItemsSelection)Doc.CreateStdSel((uint)nSelID);
					//Then we need to get root item entry for the desired page (we'll create it if needed)

	PDFXEdit.IPXV_ContentItemEntry itRootEntry = null;//Inst.CreateCIEntry();
	PDFXEdit.IPXV_ContentItemEntry itPageEntry = itRootEntry.Insert(nPage);
	//Inserting needed content items from the page
	var content = Doc.CoreDoc.Pages[nPage].GetContent(PDFXEdit.PXC_ContentAccessMode.CAccessMode_WeakClone);
	for (uint i = 0; i < content.Items.Count; i++)
	{
		//For example we will take all of the text items
		if (content.Items[i].Type == PDFXEdit.PXC_CIType.CIT_Text)
			itPageEntry.Insert(i);
	}
	//Adding selected page's root entry with added content items to the operation
	options["Entries"].Add(PDFXEdit.CabDataTypeID.dt_IUnknown).v = itPageEntry;
	//Setting the color (note that rgb notation is rgb(r,g,b) where r g b are float values from 0.0 to 1.0)
	options["FColor"].v = "#AC3312";
	//Setting mask that will tell the operation that the FColor will be modified
	options["Mask"].v = 2;
	pOp.Do();
	//Clearing the selection
	//itSel.Clear();
}
Though again, you will need a separate content item in this case.

Cheers,
Alex