Refrase: Is this correct?  SOLVED

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
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Refrase: Is this correct?

Post by jusWest »

Just upgraded the sdk to the latest version (9.0.354)

Most things seems to work, but i get an with this code:

Code: Select all

IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcPage);

// error comes here
IPXC_AnnotData_Line aData = (IPXC_AnnotData_Line)annot.Data;
the error is:
{"Unable to cast COM object of type 'System.__ComObject' to interface type 'PDFXEdit.IPXC_AnnotData_Line'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{74241EDA-26AF-4F26-89CC-DB968190332D}' failed due to the following error: Det er ingen støtte for dette grensesnittet (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}
Anybody got any ideas?

The rest of the code in the application seems to work as it should

the IPXC_AnnotData_Line interface is found in Visual Studio, and I can se propertes og an object based on it, and the cast is allowed pre runtime, but I get the abowe error when accessing the code at runtime.
Last edited by jusWest on Tue May 04, 2021 6:34 am, edited 2 times in total.
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Refrase: Is this correct?

Post by jusWest »

Ok! Since no one seems to want to touch this. Lets refrase...:

Is this the correct way of adding a Line annotation from code?
(Its based on the docs and other code found)

Code: Select all

        public IPXC_Annotation AddAnnotLine(AppAnnot dAnnot, IPXC_Page page, uint nText)
        {
            PXC_Point startPoint = new PXC_Point();
            startPoint.x = dAnnot.Rect.left;
            startPoint.y = dAnnot.Rect.top;

            PXC_Point endPiont = new PXC_Point();
            endPiont.x = dAnnot.Rect.right;
            endPiont.y = startPoint.y;

            PXC_Rect rcPage = page.get_Box(PXC_BoxType.PBox_PageBox);

            IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcPage,0);

            IPXC_AnnotData_Line aData = (IPXC_AnnotData_Line)annot.Data;

            aData.Title = "test";

            IAUX_Inst auxInst = (IAUX_Inst)_Inst.GetExtension("AUX");
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);
            //color.SetRGB(0.0f, 0.0f, 0.0f);
            color.Value = dAnnot.Color;
            aData.Color = color;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            
            PXC_AnnotBorder border = new PXC_AnnotBorder();
            border.nStyle = (PXC_AnnotBorderStyle)dAnnot.BorderStyle;
            border.nWidth = dAnnot.BorderWidth;
            aData.set_Border(border);
            annot.Data = aData;

            return annot;
        }
If so, I want to point out that everything works with the SDK, apart from
this line:

Code: Select all

            IPXC_AnnotData_Line aData = (IPXC_AnnotData_Line)annot.Data;
It resolves in the code editor, and I can access the properties of the object, so the cast works at design time, but at runtime it crashes with the above mentioned error.

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

Re: Refrase: Is this correct?

Post by Sasha - Tracker Dev Team »

Hello jusWest,

Have you checked this sample project?
https://github.com/tracker-software/PDF ... tations.cs

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: Refrase: Is this correct?

Post by jusWest »

Sasha - Tracker Dev Team wrote: Tue May 04, 2021 8:33 am Hello jusWest,

Have you checked this sample project?

Cheers,
Alex
Yes I partially got my code from there, and the only difference I can see is:

Code: Select all

            IPXC_AnnotData_Line aData = annot.Data as IPXC_AnnotData_Line;
With the use of "as" instead of a cast.

But when I use that, it fail on the next line:

Code: Select all

            aData.Title = "test";
With a "System.NullReferenceException"

I don't get whats wrong here :O
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Refrase: Is this correct?

Post by Sasha - Tracker Dev Team »

Hello jusWest,

Are you 100% sure that you are obtaining a line annotation? Does the same behavior recreate when you are using a sample from the CoreAPIDemo project?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: Refrase: Is this correct?

Post by jusWest »

I think so, this is basically how I do it:

Code: Select all

                IPXS_Inst pSInt = (IPXS_Inst)_Inst.GetExtension("PXS");

                uint nTextBox = pSInt.StrToAtom("FreeText");
                uint nCaret = pSInt.StrToAtom("Caret");
                uint nLine = pSInt.StrToAtom("Line");
                uint nMarkup = pSInt.StrToAtom("Markup");
                uint nPoly = pSInt.StrToAtom("Poly");
                uint nPopup = pSInt.StrToAtom("Popup");
                uint nSquareCircle = pSInt.StrToAtom("SquareCircle");
                uint nText = pSInt.StrToAtom("Text");
                uint nTextMarkup = pSInt.StrToAtom("TextMarkup");
                uint nInk = pSInt.StrToAtom("Ink");
                uint nLink = pSInt.StrToAtom("Link");
                
                nAnnottype = dAnnot.AnnotType;
                
                
                 if (nAnnottype > 0)
                {
                    var pPage = Doc.CoreDoc.Pages[dAnnot.Page - 1];

                    IPXC_Annotation newAnnot = null;

                    if (nAnnottype == nLine)
                    {
                        newAnnot = AddAnnotLine(dAnnot, pPage, nText);
                    }

                    int nID = _Inst.Str2ID("op.annots.addNew", false);
                    IOperation pOp = _Inst.CreateOp(nID);
                    ICabNode input = pOp.Params.Root["Input"];

                    input.Add().v = newAnnot;

                    pOp.Do();
                }
And this is the AddAnnotLine function:

Code: Select all

        public IPXC_Annotation AddAnnotLine(MyAnnot dAnnot, IPXC_Page page, uint nText)
        {
            PXC_Point startPoint = new PXC_Point();
            startPoint.x = dAnnot.Rect.left;
            startPoint.y = dAnnot.Rect.top;

            PXC_Point endPiont = new PXC_Point();
            endPiont.x = dAnnot.Rect.right;
            endPiont.y = startPoint.y;

            PXC_Rect rcPage = page.get_Box(PXC_BoxType.PBox_PageBox);

            IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcPage,0);

            //IPXC_AnnotData_Line aData = (IPXC_AnnotData_Line)annot.Data;
            IPXC_AnnotData_Line aData = annot.Data as IPXC_AnnotData_Line;

            aData.Title = "test";

            IAUX_Inst auxInst = (IAUX_Inst)_Inst.GetExtension("AUX");
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);
            //color.SetRGB(0.0f, 0.0f, 0.0f);
            color.Value = dAnnot.Color;
            aData.Color = color;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            
            PXC_AnnotBorder border = new PXC_AnnotBorder();
            border.nStyle = (PXC_AnnotBorderStyle)dAnnot.BorderStyle;
            border.nWidth = dAnnot.BorderWidth;
            aData.set_Border(border);
            annot.Data = aData;

            return annot;
        }
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Refrase: Is this correct?  SOLVED

Post by zarkogajic »

Hi JustWest,

You are sending "nText" to "newAnnot = AddAnnotLine(dAnnot, pPage, nText);" while you want to send "nLine" value.

-žarko
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: Refrase: Is this correct?

Post by jusWest »

zarkogajic wrote: Wed May 05, 2021 9:51 am Hi JustWest,

You are sending "nText" to "newAnnot = AddAnnotLine(dAnnot, pPage, nText);" while you want to send "nLine" value.

-žarko
:oops: :oops: :oops: Thank you zarkogajic, I have been staring myself blind at this.

It goes to show that an extra pair of eyes often helps.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Refrase: Is this correct?

Post by zarkogajic »

Happens to all :)

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17765
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Refrase: Is this correct?

Post by Tracker Supp-Stefan »

:)
Post Reply