Repository navigation
Read and write a page's viewports without loading the page - #115
Merged
Merged
Conversation
A page's measurement viewports (/VP) could only be reached through a loaded FPDF_PAGE, and loading a page parses its whole content stream. The engine reads every page's viewports, so a 1,000-page document parsed 1,000 pages to read one dictionary entry each. The viewport functions now have raw twins, as annotations have EPDFPage_GetAnnotRaw: EPDFPage_CountViewportsRaw, GetViewportRaw, AddViewportRaw and RemoveViewportRaw take a document and a page index and never parse the page. A raw viewport is hosted by a page built from its dictionary, and every viewport, measure and number-format accessor works on it unchanged. EPDFViewport_Close releases the host and every handle obtained through it; one left open is freed with the document. Raw and page handles share their generations, so a removal through either makes the other side's handles stale. Each page function and its raw twin share one body.
bobsingor
added a commit
to embedpdf/embed-pdf-viewer
that referenced
this pull request
Nov 8, 2026
The release has the raw viewport functions (embedpdf/runtime#115) and the upstream sync to 6688c576f (Nov 6 2026). The bindings generated from it are the ones already committed.
lucapivato
pushed a commit
to iceteagroup/embed-pdf-viewer
that referenced
this pull request
Nov 8, 2026
The fork branch embedpdf/feature/raw-viewports (embedpdf/runtime#115) adds EPDFPage_CountViewportsRaw, GetViewportRaw, AddViewportRaw, RemoveViewportRaw and EPDFViewport_Close. The runtime pin moves once that release is out.
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.
A page's measurement viewports (
/VP) could only be read and written through a loadedFPDF_PAGE, and loading a page parses its whole content stream. The engine reads every page's viewports, so opening a 1,000-page document parsed 1,000 pages to read one dictionary entry each, and "apply this scale to all pages" parsed every page again to write it.Now the viewport functions have raw twins, the way annotations have
EPDFPage_GetAnnotRawand friends. They take a document and a page index, and they never parse the page:EPDFPage_CountViewportsRaw(doc, page_index)reads the size of/VPfrom the page dictionary. Nothing else is built, so a pass over every page skips the pages without viewports for the price of a dictionary lookup.EPDFPage_GetViewportRawandEPDFPage_AddViewportRawreturn anEPDF_VIEWPORThosted by a page built from its dictionary and never parsed, asEPDFPage_GetAnnotRawbuilds one. EveryEPDFViewport_*,EPDFMeasure_*andEPDFNumberFormat_*accessor works on it unchanged.EPDFPage_RemoveViewportRawremoves an entry.EPDFViewport_Closereleases a raw viewport's host and every handle obtained through it (its measure and formats). The document's measure registry keeps the open hosts, so one left open is freed with the document. A viewport of a loaded page still belongs to its page; closing one does nothing.Each raw function opens the document's view scope, so in a layer it reads the page in the layer, and a write promotes exactly the page, as through a loaded page. Raw handles and page handles share their generations (both key them by the page's object number), so a removal through either makes the other side's handles stale.
The four page functions and their twins share one body each, taking a
CPDF_Page: a loaded page or the raw host. The page functions behave as before.There is no raw
FindViewport: the engine picks the viewport under a point itself.The engine side moves viewports onto the page layout and reads them through these functions (plan: measurement viewports on the layout). Pin this there after release.
Tests
RawViewportsReadWhatTheLoadedPageReads: count, bbox, name and measure through a raw handle match the loaded page; bad page and entry indexes; closing a loaded page's viewport does nothing; a raw handle left open is freed with the document.RawViewportWritesShareGenerationsWithLoadedPages: raw adds show on the loaded page; a raw removal makes raw and loaded handles stale, and a loaded removal makes raw handles stale.RawLayerReadsPromoteNothingAndWritesOnlyPage: in a layer, raw reads promote nothing, a raw add promotes exactly the page, an earlier raw handle follows the page into the layer, and the delta reopens with both viewports.BadArgumentsAndRejectedWritescovers the raw functions andEPDFViewport_Close(NULL).epdf_c_api_test.clists the five new exports.RawViewportsReadWhatTheLoadedPageReadsthe document read through raw handles leaves 0 objects; the 5 are the documentBase()builds.RenderHelloWorldWithFlagsandCaptionAppearanceGolden.