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
Simon