Page 1 of 1

Annotations within innerDocWindowRect

Posted: Wed Jan 11, 2023 8:28 am
by AnKeilha
Hello,
I would like to find out which PDF annotations are visible (to the user) within the innerDocWindowRect.

Best regards,
Andreas

Re: Annotations within innerDocWindowRect

Posted: Wed Jan 11, 2023 1:16 pm
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.

Re: Annotations within innerDocWindowRect

Posted: Thu Jan 12, 2023 9:40 pm
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.

Re: Annotations within innerDocWindowRect

Posted: Mon Oct 14, 2024 1:08 pm
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

Re: Annotations within innerDocWindowRect

Posted: Mon Oct 14, 2024 2:03 pm
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

Re: Annotations within innerDocWindowRect

Posted: Mon Oct 14, 2024 6:19 pm
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,