Changing stamp colour does not refresh

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

Changing stamp colour does not refresh

Post by lidds »

I am using the following code to change the colour of selected annotations and stamps. This code works perfectly, apart from one issue.

If I pick a stamp (obviously the stamp has to be created using your cmd.document.createStampFromSel command) running the code, it DOES change the colour of the stamp, but this is not instantly shown. However if I select and move the stamp location slightly then the stamp colour changes. It is almost like I need to do a refresh or something?

Thanks

Simon
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Changing stamp colour does not refresh

Post by Sasha - Tracker Dev Team »

Hello Simon,

You forgot to add the code itself.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Changing stamp colour does not refresh

Post by lidds »

Sorry Alex,

Please see below:

Code: Select all

   Public Sub changeSelAnnotColour(ByVal newColour As Color)
        Dim pSInt As PDFXEdit.IPXS_Inst = DirectCast(Me.docPreview.Inst.GetExtension("PXS"), PDFXEdit.IPXS_Inst)
        Dim nID As Integer = Me.docPreview.Inst.Str2ID("op.annots.setProps", False)
        Dim oper As PDFXEdit.IOperation = Me.docPreview.Inst.CreateOp(nID)
        Dim input As PDFXEdit.ICabNode = oper.Params.Root("Input")
        Dim options As PDFXEdit.ICabNode = oper.Params.Root("Options")
        Dim commands As String = Me.docPreview.Inst.ID2Str(oper.ID)

        Dim sel As PDFXEdit.IPXV_DocSelection = Me.docPreview.Doc.ActiveSel
        Dim annotSel As PDFXEdit.IPXV_AnnotSelection = CType(sel, PDFXEdit.IPXV_AnnotSelection)

        Dim annotType As String = Nothing
        Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
        color.Value = "rgbd(" & newColour.R.ToString & "," & newColour.G.ToString & "," & newColour.B.ToString & ")"

        If annotSel IsNot Nothing Then
            If annotSel.Items.Count <> 0 Then
                For i As UInteger = 0 To annotSel.Items.Count - 1

                    Dim annot As IPXC_Annotation = annotSel.Items(i)
                    annotType = pxsInst.AtomToStr(annot.Type)

                    If annotType = "Stamp" Then
                        Dim objApp As Object = annot.Handler.GetAppearance(annot, Nothing)
                        Dim varApp As IPXS_PDFVariant = CType(objApp, IPXS_PDFVariant)
                        If (varApp Is Nothing) Then
                            Return
                        End If

                        Dim xForm As IPXC_XForm = annot.Page.Document.GetXForm(varApp)
                        If (xForm Is Nothing) Then
                            Return
                        End If

                        Dim content As IPXC_Content = xForm.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone)
                        Dim cc As IPXC_ContentCreator = annot.Page.Document.CreateContentCreator
                        cc.Attach(content)
                        cc.ResetAllStatesToDefault()
                        ModifyCState(content, newColour.R.ToString, newColour.G.ToString, newColour.B.ToString)
                        cc.SetStrokeColorRGB(color.RGB)
                        cc.SetColorRGB(color.RGB)
                        xForm.SetContent(cc.Detach)
                    Else
                        If annot.IsMarkup Then
                            input.Clear()
                            input.Add().v = annot

                            If annotType = "Highlight" Then
                                options("FColor").v = "rgb(" & newColour.R.ToString & "," & newColour.G.ToString & "," & newColour.B.ToString & ")"
                                options("Mask").v = PXV_OpModifyAnnotMaskFlags.OpModifyAnnot_FColor
                            Else
                                Dim annotOwner As PDFXEdit.IPXC_Annotation = Nothing

                                Dim annotLoop As PDFXEdit.IPXC_Annotation = annot
                                Do Until annotLoop.ReplyTo Is Nothing
                                    annotOwner = annotLoop.ReplyTo
                                    annotLoop = annotOwner
                                    input.Add().v = annotOwner
                                Loop

                                If annotType = "Text" Then
                                    annotLoop = annot
                                    Do Until annotLoop.Popup Is Nothing
                                        annotOwner = annotLoop.Popup
                                        annotLoop = annotOwner
                                        input.Add().v = annotOwner
                                    Loop

                                    options("SColor").v = "rgb(" & newColour.R.ToString & "," & newColour.G.ToString & "," & newColour.B.ToString & ")"
                                    options("FColor").v = "rgb(" & newColour.R.ToString & "," & newColour.G.ToString & "," & newColour.B.ToString & ")"
                                    options("Mask").v = PXV_OpModifyAnnotMaskFlags.OpModifyAnnot_SColor + PXV_OpModifyAnnotMaskFlags.OpModifyAnnot_FColor
                                Else
                                    options("SColor").v = "rgb(" & newColour.R.ToString & "," & newColour.G.ToString & "," & newColour.B.ToString & ")"
                                    options("Mask").v = PXV_OpModifyAnnotMaskFlags.OpModifyAnnot_SColor
                                End If
                            End If

                            oper.Do()
                        End If
                    End If
                Next
            End If
        End If
    End Sub
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Changing stamp colour does not refresh

Post by Sasha - Tracker Dev Team »

Hello Simon,

Can you please arrange that code into a small working sample so that I can try that here?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Changing stamp colour does not refresh

Post by lidds »

Alex,

Please see attached project and also a video to illustrate.

Thanks

Simon
Attachments
Video.zip
(2.39 MiB) Downloaded 67 times
PDFXChangeDemo.zip
(608.99 KiB) Downloaded 68 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Changing stamp colour does not refresh

Post by Sasha - Tracker Dev Team »

Hello Simon,

You will have to invalidate these annotations and pages for correct redraw:

Code: Select all

If annotSel.Items.Count <> 0 Then
Dim ipi As IPXV_InvalidatePagesInfo = docPreview.Doc.CreateInvPagesInfo()
For i As UInteger = 0 To annotSel.Items.Count - 1
'...
cc.SetColorRGB(color.RGB)
xForm.SetContent(cc.Detach)
ipi.InvalidateAnnot(annot)
Else
'...
Console.WriteLine("Annot Type: " & annotType)
Next
docPreview.Doc.InvalidatePages(ipi)
End If
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
lidds
User
Posts: 510
Joined: Sat May 16, 2009 1:55 pm

Re: Changing stamp colour does not refresh

Post by lidds »

Alex,

Thank you for your help, that has fixed it.

As always brilliant support.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Changing stamp colour does not refresh

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply