How do I modify text color (and other attributes) under a given rectangle?

58 views
Skip to first unread message

Support

unread,
May 13, 2008, 2:01:42 PM5/13/08
to PDFTron PDFNet SDK
Q: One of our requirements is to change the color of selected text (as
we are creating links). We have used the sample code from PDFNet KB
(search for "How can I modify text color under a given rectangle").

This works well most of the time, but some of the time when the
selected text is only part of the underlying text run, we are finding
the spacing between characters is changing, thus causing the text run
to expand on the page.

I have attached a demonstration of this behavior.
PDFViewSimple_CS.zip (http://groups.google.com/group/pdfnet-sdk/web/
PDFViewSimple_CS.zip) contains an updated version of the sample
provided by you. I have changed the tool mode to SelectByStruct, and
added a menu item Edit->TurnTextBlue to change the coloring of the
selected text blue. This uses a slightly updated version of the code
found on the web link above (to handle multiple selection rectangles).

To reproduce the behavior, open the included 'sheep.pdf', and select
the word "Worth". Then click TurnTextBlue. Notice how the text run
"Market: Two Cents Worth" has now expanded, and the selection
rectangle no longer sits directly above the word "Worth".

I do not sufficiently understand the sample code to try and implement
a fix for this, but I presume it will be able to be fixed with a
change to the sample code, rather than the API.

Please advise what the fix for this will be.

------
A: The problem is that the
"new_element.SetPosAdjustment(element.GetPosAdjustment())" is called
for each character in the overlapping text-run instead of only once
per text-run.

The sample project (http://groups.google.com/group/pdfnet-sdk/web/
PDFViewSimple_CS.zip) is modified to reflect this change.
Reply all
Reply to author
Forward
0 new messages