Repository navigation
fix(document): hinted remote files find pages without walking the page tree (#417) - #419
Merged
Merged
Conversation
…e tree (#417) #410 made PdfPageCollection.IndexOf and TryGetPage answer from the hint tables, but only for pages the hints had already handed out. Any other page object (a structure element's Pg, a link's or an outline item's destination page) fell back to walking the page tree, which needs the main cross-reference section at the end of a remote linearized file. In the browser that throws PdfRangeNotLoadedException. - HintedPageList maps page object numbers to pages (Table F.4 items 1 and 2) and finds a page by its loaded page object. IndexOf and TryGetPage use it while the hints are in use and never read the tree. - PdfExplicitDestination.PageIndex, TargetKind and StructureElement answer a page reference from the hints by its object number, without reading the page. - New PdfDocument.ReadAsync<T> runs a synchronous read and fetches asynchronously whatever it misses. Use it for reads that need more of the file (every page, the outline, the structure tree, the name trees). PdfRangeNotLoadedException now points to it. - DocumentSession.ReadAsync runs a remote document's reads through it, so a tagged page's accessible tree and text load in the browser. - Conformance rows G.4 and F.4.2 updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #417.
Root cause
#410 (PR #413) made
PdfPageCollection.IndexOf(CosDictionary)andTryGetPageanswer from the hint tables, but only for pages the hints had already handed out (HintedPageList._indexes). A page object reached any other way fell back toCurrent, a full walk of the page tree. In a linearized file the page tree comes after the pages (F.3.10), so the walk needs the main cross-reference section at the end of the file. Examples: a structure element's/Pg, a link's or outline item's destination page, a widget's page,CreateDestination. In the browser (SynchronousRangeFetchoff) the walk throwsPdfRangeNotLoadedException. The outline, the structure tree and the name trees also come after the pages, and only a synchronous read could reach them.Audit (core callers of the full page-tree walk while hints are in use)
Pages.CountNforeach PagesPdfDocument.ReadAsync, and the miss message names itIndexOf(CosDictionary)/IndexOf(PdfPage)(StructureLayout, AnnotationLayerInvalidateField,CreateDestination,FieldCreation,Remove)TryGetPage(structure/PginPdfStructureElement,StructureContext.FindPage,MarkedContentIndex,ShownItems)IndexOfPdfExplicitDestination.PageIndex/TargetKind/StructureElement(links, outline items, GoTo actions,GetDestinationViewport)IndexOf(walk)PdfDocument.ReadAsync(fetches the main section and the objects when needed)StructureContext.IndexParentTreePagesrepair,AnnotationIndexowners, PDF/A and PDF/UA checkers, save)ReadAsyncChanges
HintedPageList.TryGetIndex(CosReference)maps page object numbers to pages.Find(CosDictionary)finds a page by a loaded page object; the object cache keeps every object, so identity is stable.PdfPageCollectiongetsHintedIndexOf(CosDictionary)(validated throughGet; rejects the hints on failure, as before) andHintedIndexOf(CosReference).IndexOfandTryGetPageuse them and never walk the tree while the hints are in use.PdfExplicitDestinationanswers a page reference from the hints.PdfDocument.ReadAsync<T>(Func<PdfDocument, T>, CancellationToken). It runs a synchronous read, fetching what it misses asynchronously (HttpRangeSource.RunAsync), and runs once for a local document. This is the async path for anything that needs more than one page. It stays inside the existing prefetch boundary: the same "run synchronous code without blocking, fetch the miss, run it again" mechanism asOpenAsyncandPrefetchAsync, made available for any read.PdfRangeNotLoadedException's message and docs point toReadAsync.DocumentSession.ReadAsyncruns a remote document's reads throughPdfDocument.ReadAsync, in both cooperative and background modes. A tagged remote page's layout (accessible tree, text selection) needs the structure tree, and now loads in the browser.Tests
All tests open a remote linearized file with
WithSynchronousRangeFetch(false). The newTaggedLinearizedFileis 30 pages, tagged, with links, an outline and a named destination.HintedPageTreeTests.Enumerating_the_pages_goes_through_the_hinted_pages_and_never_reads_the_page_tree: a sync enumeration throws, namingReadAsync. Enumeration throughReadAsyncgives every page and its text, and fetches neither the page tree nor the main cross-reference section....A_link_finds_its_page_from_the_hints_and_a_named_destination_resolves_through_the_async_read...The_outline_items_find_their_pages_from_the_hints...A_structure_element_finds_its_page_from_the_hints_and_a_tagged_page_extracts_its_layout: page 20's/Pgresolves before the hints hand out page 20....A_local_document_runs_an_async_read_onceDocumentSessionTests.A_remote_linearized_tagged_page_loads_its_accessible_tree_and_links_without_synchronous_fetches(cooperative and background).Each test checks that the hints are still in use and the page tree root was never loaded. On the old code, 6 of the 9 core cases and both viewer cases fail.
Local gate: build with
-warnaserrorpasses,Broadside.Core.slnfhas 17184 passed and 0 failed, and ConformanceCheck, format and the ADR-reference check pass.Follow-up
AnnotationLayer.Activateresolves a named destination synchronously in the UI event. For a remote file in the browser, that name tree has not arrived. Filed as #420.🤖 Generated with Claude Code