Extract link annotation text, change text color
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.
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.
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Extract link annotation text, change text color
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)?
-ž
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)?
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
Hello zarkogajic,
This should help:
viewtopic.php?f=66&t=32582&p=133499&hil ... xt#p133499
Cheers,
Alex
This should help:
viewtopic.php?f=66&t=32582&p=133499&hil ... xt#p133499
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi Alex,
ok, will try...
Once I have that text - how to change the color of it?
-ž
ok, will try...
Once I have that text - how to change the color of it?
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
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)?
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
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)?
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
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
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?
-ž
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?
-ž
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi support,
ping....
-ž
ping....
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Alex,
Hm ..
I'm (basically) after this:
And then: character color changed:
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
Hm ..
I'm (basically) after this:
And then: character color changed:
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
Last edited by zarkogajic on Thu Dec 12, 2019 4:05 pm, edited 1 time in total.
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
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
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
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi Alex,
Thanks.
I want to ensure link annotations are in blue text color (of course, if the annotation is "above" text).
-ž
Thanks.
I want to ensure link annotations are in blue text color (of course, if the annotation is "above" text).
-ž
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi Alex,
Ping...
-ž
Ping...
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi Alex,
So, this is why you do internally to have this (?):
?
-ž
So, this is why you do internally to have this (?):
?
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
Hello žarko,
I'm not sure that I have understood your question.
Cheers,
Alex
I'm not sure that I have understood your question.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
Hi Alex,
I guess I'm asking for some code samples to do:
-ž
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
-ž
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
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
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
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
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
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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 1371
- Joined: Thu Sep 05, 2019 12:35 pm
Re: Extract link annotation text, change text color
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
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
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Extract link annotation text, change text color
Hello zarkogajic,
If it were that easy - I would have suggested it earlier.
Here's what I have in my samples:
Though again, you will need a separate content item in this case.
Cheers,
Alex
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();
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ