| 3844 | } |
| 3845 | |
| 3846 | function _getWidgetPage(pdfDoc, pages, widget) { |
| 3847 | try { |
| 3848 | const pRef = widget.P?.(); |
| 3849 | if (pRef) { |
| 3850 | for (const page of pages) { |
| 3851 | if (page.ref === pRef) return page; |
| 3852 | } |
| 3853 | } |
| 3854 | } catch { |
| 3855 | /* fall through */ |
| 3856 | } |
| 3857 | |
| 3858 | try { |
| 3859 | const pRef = widget.dict?.get?.(PDFName.of("P")); |
| 3860 | if (pRef) { |
| 3861 | for (const page of pages) { |
| 3862 | if (page.ref === pRef) return page; |
| 3863 | } |
| 3864 | } |
| 3865 | } catch { |
| 3866 | /* fall through */ |
| 3867 | } |
| 3868 | |
| 3869 | // Fallback: search page annots |
| 3870 | try { |
| 3871 | for (const page of pages) { |
| 3872 | const annots = page.node.lookupMaybe(PDFName.of("Annots"), PDFArray); |
| 3873 | if (!annots) continue; |
| 3874 | |
| 3875 | for (let i = 0; i < annots.size(); i++) { |
| 3876 | const ref = annots.get(i); |
| 3877 | if (ref === widget.ref) return page; |
| 3878 | } |
| 3879 | } |
| 3880 | } catch { |
| 3881 | /* fall through */ |
| 3882 | } |
| 3883 | |
| 3884 | return null; |
| 3885 | } |
| 3886 | |
| 3887 | function _drawWidgetBox(page, rect) { |
| 3888 | try { |