Change color of Callout text

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
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Change color of Callout text

Post by lidds »

Hi,

I am using the following code to change the text color to grey. This works fine if the user changes when placing the annot element changed the font type, color, bold etc. but not if just entering text as is.

I believe this is due to the fact that when a user modified the font style, color etc. it changes the text content of the annot to a RichText format, instead of a normal string value of text for the content.

I was hoping that someone could advise me on how to modify the below code to change the text text color, regardless of if it is of RichText format or string content?

Code: Select all

    Public Sub changeTextColour(ByRef annot As IPXC_Annotation, ByVal hexColour As String)
        Dim op As PDFXEdit.IOperation = Me.docPreview.Inst.CreateOp(Me.docPreview.Inst.Str2ID("op.annot.setData"))
        Dim cdoc As PDFXEdit.IPXC_Document = Me.docPreview.Doc.CoreDoc
        Dim ad As PDFXEdit.IPXC_AnnotData_Markup = CType(annot.Data, PDFXEdit.IPXC_AnnotData_Markup)
        Dim rc As String = ad.RichContent
        Debug.WriteLine(ad.Contents.ToString)

        Dim regExMatches As MatchCollection = Regex.Matches(rc, "(color)(:)(#{1}(?:[A-F0-9]){6})(?![0-9A-F])")

        For Each i As Match In regExMatches
            rc = rc.Replace(i.Value.ToString, "color:" & hexColour)
        Next

        Dim rtf As String = pxcInst.ConvertRC2RTF(cdoc, rc, "", CType(PDFXEdit.PXC_ConvertRCFlags.PXC_ConvertRC_AnnotText, Integer))
        ad.RichContent = pxcInst.ConvertRTF2RC(cdoc, rtf, CType(PDFXEdit.PXC_ConvertRCFlags.PXC_ConvertRC_AnnotText, Integer))
        Dim pr As PDFXEdit.ICabNode = op.Params.Root
        pr("Input").Clear()
        pr("Input").Add.v = annot
        pr("Options.NewData").v = ad
        op.Do(0)
    End Sub
Thanks

Simon
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Change color of Callout text

Post by lidds »

I was wondering if possible for someone to have a look at this as it's the last thing I need to fix before releasing my next version.

Thanks

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

Re: Change color of Callout text

Post by Vasyl-Tracker Dev Team »

You also need to use IPXC_AnnotData_FreeText.DefaultTextColor:

Code: Select all

Dim ad As PDFXEdit.IPXC_AnnotData_FreeText = CType(annot.Data, PDFXEdit.IPXC_AnnotData_FreeText)
Dim auxInst As PDFXEdit.IAUX_Inst = Me.docPreview.Inst.GetExtension("AUX")

Dim clr As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.CreateColor.ColorType_RGB)
clr.SetRGB(0.5, 0.5, 0.5)
ad.DefaultTextColor = clr

MakeGrayTextInRC(ByRef ad)

...
PS: sorry for possible syntax-issues in the code-snipped above, because I'm not a good VB-programmer.. :wink:
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.
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Change color of Callout text

Post by lidds »

Thank you Vasyl, this worked perfectly
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Change color of Callout text

Post by Tracker Supp-Stefan »

:)
Post Reply