PXC_Rect and InsertNewAnnot  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
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello,

i have a question about how exactly the PXC_Rect determines the position and size of an annotation when using the InsertNewAnnot Method from PXC_Page. The relevant code sample:

Code: Select all

            
            PXC_Rect pRect = new PXC_Rect
            {
                left = 300,
                bottom = 0,
                right = -300,
                top = 0
            };

            IPXS_Inst pSInt = (IPXS_Inst)pdfCtl.Inst.GetExtension("PXS");
            uint nStamp = pSInt.StrToAtom("Stamp");
            IPXC_Page page = pdfCtl.Doc.CoreDoc.Pages[pageNum]; //pageNum is a parameter given to this method

            var annot = page.InsertNewAnnot(nStamp, ref pRect, 0);

            return annot;
With a rectangle like that, the annotation is placed in the lower left corner. I can't seem to grasp what exactly each of the coordinates of the rectangle affect the position and size of the annotation.

Every help is appreciated, thanks!

With kind regards,
Dennis
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Hello Dennis,

Well the coordinates of the annotation is in the PDF coordinate system. The (0;0) coordinate is in the bottom left corner. Also the annotation placement is being done within the Media Box of the page.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

thank you for the fast reply. I don't quiet understand what you mean with "annotation placement is being done within the Media Box of the page"...

Can you further specify how the PDF Coordinate System works? I looked here https://sdkhelp.pdf-xchange.com/view/PXV:PXC_Rect to find out how the coordinates of a rectangle works. Looking at that information i should just specify the upper left and the lower right corner to where i want my annotation to be placed, as the parameter for the this method: https://sdkhelp.pdf-xchange.com/vi ... rtNewAnnot. But that works rather unintuitive.

Unfortunatly i didn't find anything in the forums regarding that topic. A clarification is appreciated, thanks!

Greetings,
Dennis
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello again!

A quick update from my side. I did manage to figure the coordinates out better. I still have some question marks on my head, but i think i can manage somehow.

Would still appreciate some more information, but i know that sometimes work is just too busy. So don't mind just heading on to the next topic.

Thank you anyway, Alex!

Edit: My solution:

Code: Select all

        private PXC_Rect GetRectByPoint(int width, int height, int x, int y)
        {
            IPXC_Page page = pdfCtl.Doc.CoreDoc.Pages[0];
            page.GetDimension(out double pageWidth, out double pageHeight);

            PXC_Rect pRect2 = new PXC_Rect
            {
                left = 0 - pageWidth + (width) + x,
                bottom = 0 - pageHeight + (height) + y,
                right = pageWidth + x,
                top = pageHeight + y
            };

            return pRect2;
        }


With best regards,
Dennis
Last edited by DeKo on Tue Apr 24, 2018 8:45 am, edited 1 time in total.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Hello Dennis,

You can read more about the PDF Coordinate system in the PDF Specification.
As for the annotation placement - I don't see why there would be a problem - just specify the rectangle (like in the sample in the second link) and it should be placed in it.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

i need to bug you again. So i want to place a stamp on the top left corner. If my understanding is correct, that would be in the coordinates (0 ; height of media box). I then get the point in the page with the pdfCtl.Doc.ActiveView.PagesView.Layout.HitTest method. If i follow the example and try to make a rectangle for the top left corner of the page, i would go with this:

Code: Select all

            PXC_Rect pRect2 = new PXC_Rect
            {
                left = ptPagePoint.x,
                right = ptPagePoint.x + width, //width is the width of my picture
                top = ptPagePoint.y - height, //same as width
                bottom = ptPagePoint.y
            };
So, my expectation would be, that i would get a stamp that has my specified width and height in the top left corner. But its placed on the lower right corner, the wrong dimensions and only a small part is visible.

Maybe i am misunderstanding something?

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

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Hello Dennis,

1) The correct way of setting the rectangle is that the top is greater then bottom (as in the PDF coordinate system). The way that you have specified it - it will be fixuped anyways, but please use the correct method.

2) There is a sample by the link that you mentioned here:
https://sdkhelp.pdf-xchange.com/vi ... not#Sample
It does exactly what you need - notice the HitTestPage code:

Code: Select all

//Converting screen point to PDFXEdit client point
pdfCtl.Doc.ActiveView.PagesView.Obj.ScreenPtToClient(ptIn, out ptRes);
//And then checking whether it is on page and returning it in page coordinate system if so
return pdfCtl.Doc.ActiveView.PagesView.Layout.HitTest(ptRes, out ptPagePoint);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

im really sorry, but it just doesn't work out. It's really confusing with all those different points and rectangles (tagPoint, PXC_Point, _POINTL, and so on...) I can't seem to find the right coordinate for the top left corner. I understand the example and i understand how it should work - but it just does not. So, right now im debugging the whole proccess.

Let me try to explain as much as possible. I am getting a rectangle with:

Code: Select all

var rect = pdfCtl.Doc.ActiveView.PagesView.Layout.GetPageRect(0);

//Coordinates are:
bottom: 937
left: 5
right: 665
top: 5
Based on that, i create a point in 5/5, which does not pass the HitTest. If i test 6/6, the HitTest passes, so i can assume that this are the coordinates of one of the corners in the page.
Next step, after i get that point in the page, which is (0 ; 727) (both values rounded down) i calculate my rectangle in which i place the annotation (in this case a custom stamp) with this code:

Code: Select all

            PXC_Rect pRect = new PXC_Rect
            {
                bottom = ptPagePoint.y - height, // height is 300 in my case
                left = ptPagePoint.x,
                right = ptPagePoint.x + width, // width is 300 in my case
                top = ptPagePoint.y
            };
This results in following coordinates (all values rounded down again):

Code: Select all

bottom = 427,
left = 0,
right = 300,
top = 727
So, it is somehow in the top left corner (but with about a 1/5 of the page as distance). What really is weird to me, if i would double my width and height, my annotation should double in size. It indeed does, BUT its position changes diagonally and is now rather lower right from the center... And this just feels wrong to me.

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

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Hello Dennis,

I've been implementing a CoreAPI sample for some time now, and now, I think it's time to publish it, as it has some samples available already. It has a sample, that adds stamp on page in the top left corner in it. You can look at the code and try it for yourself ("Add Draft stamp from a standard collection by Stamp ID"). https://github.com/tracker-software/PDF ... oreAPIDemo
To launch the sample though you will have to register the PDFXCoreAPI.xxx.dll

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

i will check that out and if anything comes up i will let you know.

Thank you for bearing with our problems and trying your best to help, i appreciate it a lot!

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

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Do check it out and see whether it works for you.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

after looking at the sample, unfortunatly im still confused. I checked all stamp samples and all PXC_Rect Objects had left = 0 and top = 800. But all stamps from the 4 examples had different position. How come so? The coordinates of the top left corner of the rectangle is (0 ; 800) and yet all stamps are at a different position.

Am i missing something general / simple here? Or is that kind of a bug on my side?

Edit: Sorry, the first to stamps actually have the same position. But the other two, which are loaded from file, have a different position each.

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

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Hello Dennis,

Have you looked into the file itself? Notice that the stamps were scaled along with the white areas around them.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

Though from the second though - you are right - the annotation's rectangle is being trimmed by Y - will check that out.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXC_Rect and InsertNewAnnot  SOLVED

Post by Sasha - Tracker Dev Team »

Hello Dennins,

Found a cause of this - you should also set the BBox of the stamp data. Updated both samples and pushed to Git.

Code: Select all

stampData.set_BBox(rc); //Stamp rectangle boundaries
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DeKo
User
Posts: 56
Joined: Thu Sep 28, 2017 9:45 am

Re: PXC_Rect and InsertNewAnnot

Post by DeKo »

Hello Alex,

thank you very much! Now its perfect. I wouldn't find that by myself.

I was fighting 2 days with this, i am really glad for your help!


Thank you again and greetings,
Dennis
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXC_Rect and InsertNewAnnot

Post by Sasha - Tracker Dev Team »

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