Annotations within innerDocWindowRect

PDF-XChange Editor SDK for Developers

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

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
AnKeilha
User
Posts: 70
Joined: Fri Apr 27, 2018 11:17 am

Annotations within innerDocWindowRect

Post by AnKeilha »

Hello,
I would like to find out which PDF annotations are visible (to the user) within the innerDocWindowRect.

Best regards,
Andreas
AnKeilha
User
Posts: 70
Joined: Fri Apr 27, 2018 11:17 am

Re: Annotations within innerDocWindowRect

Post by AnKeilha »

Alternatively: It would be sufficient for us to find out the upper left and lower right corners (as PDF coordinates with respect to the PDF currently displayed) of what is currently visible for the user.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: Annotations within innerDocWindowRect

Post by Vasyl - PDF-XChange »

Hi Andreas

You may do it by the following procedure:

Code: Select all

public static tagRECT IntersectRects(tagRECT r1, tagRECT r2)
{
    tagRECT res;
    res.left = Math.Max(r1.left, r2.left);
    res.right = Math.Min(r1.right, r2.right);
    if (res.right < res.left)
        res.right = res.left;
    res.top = Math.Max(r1.top, r2.top);
    res.bottom = Math.Min(r1.bottom, r2.bottom);
    if (res.top > res.bottom)
        res.top = res.bottom;
    return res;
}

public bool GetVisibleAnnots(IPXV_Document doc, ref List<IPXC_Annotation> visibleAnnots)
{
    visibleAnnots.Clear();
    if (doc == null)
        return false;

    IPXC_Document coreDoc = doc.CoreDoc;

    IPXV_DocumentView docView = doc.ActiveView;
    if (docView == null)
        return false;
    IPXV_PagesView pagesView = docView.PagesView;
    if (pagesView == null)
        return false;

    IPXC_OCContext ocCtx = pagesView.OCContext;

    tagRECT viewRect = pagesView.Obj.ClientRect;

    IPXV_PagesLayoutManager pagesLayout = pagesView.Layout;

    IPXV_PagesLayoutRegions visibleRegions = pagesLayout.LayoutRegions;
    uint rgnCount = visibleRegions.Count;
    for (uint i = 0; i < rgnCount; i++)
    {
        PXV_PagesLayoutRegion rgn = visibleRegions[i];

        uint pageIndex = rgn.nPage;
        if ((rgn.rcVisibleRect.right - rgn.rcVisibleRect.left) < 1 || (rgn.rcVisibleRect.bottom - rgn.rcVisibleRect.top) < 1)
            continue; // page is outside of current view area (but decorative page-shadow can be visible)

        IPXC_Page page = coreDoc.Pages[pageIndex];
        IPXC_AnnotsList annots = page.GetAnnotsList();
        if (annots == null)
            continue;

        uint annotsCount = annots.Count;
        for (uint j = 0; i < annotsCount; j++)
        {
            IPXC_Annotation annot = annots[i];
            if (!ocCtx.IsAnnotVisible(coreDoc, annot))
                continue; // annot is hidden
            PXC_Rect annotRectOnPage = annot.get_Rect();
            tagRECT viewAnnotRect = pagesLayout.PageRectToDeviceRect(pageIndex, ref annotRectOnPage, true);
            tagRECT rc = IntersectRects(viewAnnotRect, rgn.rcVisibleRect);
            if ((rc.right - rc.left) < 1 || (rc.bottom - rc.top) < 1)
                continue; // there is no intersection between annot-rect and visible part of page

            visibleAnnots.Add(annot);
        }
    }

    return (visibleAnnots.Count != 0);
}
Cheers.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
AnKeilha
User
Posts: 70
Joined: Fri Apr 27, 2018 11:17 am

Re: Annotations within innerDocWindowRect

Post by AnKeilha »

Hello,
I have been trying to use DevicePointToPagePoint to translate device coordinates to PDF coordinates. Can I do this using Javascript?

Best regards,
Andreas
AnKeilha
User
Posts: 70
Joined: Fri Apr 27, 2018 11:17 am

Re: Annotations within innerDocWindowRect

Post by AnKeilha »

Hello again,
the problem from my previous comment has only indirectly to do with the overall issue of this post. => I will create a separate post for my question (see viewtopic.php?t=44190 ).

Regards,
Andreas
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10953
Joined: Wed Jan 03, 2018 6:52 pm

Re: Annotations within innerDocWindowRect

Post by Daniel - PDF-XChange »

Hello, AnKeilha

Thank you for the clarification there, I will bring the dev team attention to the other post specifically, so that the extra details in here do not detract from the discussion.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply