Integrera PDFium VCL Component-flöden i Delphi- och C++Builder-applikationer, eller PDFium LCL Component-flöden i Lazarus/FPC, med källkodskomponenter för visning, rendering, formulär, utskrift, preflight-rapporter och standardinriktad validering.
Den här artikeln är skriven för developers building document viewers that must feel responsive on large PDFs and high-DPI displays. Den behandlar render cache and zoom performance som produktionsnära dokumentteknik, inte som ett isolerat komponentanrop.
Den praktiska risken är att zooming can appear fast in a sample but stutter under large pages, thumbnails, annotations, continuous scrolling, or memory pressure. Därför behöver flödet ett skrivet kontrakt, observerbar diagnostik och realistiska regressionsfiler.
Arkitekturbeslut
Define cache policy as viewer behavior. cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state / memory budget, eviction strategy, thumbnail sharing, and prefetch distance
- cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state
- memory budget, eviction strategy, thumbnail sharing, and prefetch distance
- progressive rendering behavior for fast preview versus final-quality output
- cancellation rules when users scroll, resize, search, or change zoom quickly
Implementeringsflöde
Measure the interaction path, not only render time. Ordningen nedan gör arbetsflödet granskbart för Delphi- och C++Builder-team.
- record render requests through one queue instead of direct control event handlers
- reuse cached bitmaps only when the key fully matches the visible state
- render low-latency placeholders before high-quality pages when appropriate
- cancel stale jobs and evict pages outside the viewport and prefetch window
- measure frame latency and memory during realistic scroll and zoom sequences
Valideringsbevis
Performance evidence users can feel. Behåll dessa fält tillsammans med utdata eller supportunderlaget.
- cache hit rate, render latency, queue depth, cancellation count, and memory peak
- viewport size, zoom level, DPI, page dimensions, and color-filter state
- time to first preview and time to final-quality render
- eviction and prefetch behavior during continuous scrolling
Caching is a user-experience feature
A render cache should balance page quality, memory budget, cancellation, invalidation, and perceived latency. The viewer needs to cancel stale work when the user scrolls or zooms rather than finishing irrelevant renders.
Profile ownership and versioning
A named, versioned profile is easier to review than options scattered across forms, scripts, and batch parameters. It also makes support reports readable when customers use older templates or policies.
- cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state
- memory budget, eviction strategy, thumbnail sharing, and prefetch distance
- progressive rendering behavior for fast preview versus final-quality output
- cancellation rules when users scroll, resize, search, or change zoom quickly
- cache hit rate, render latency, queue depth, cancellation count, and memory peak
- viewport size, zoom level, DPI, page dimensions, and color-filter state
Tekniska granskningsnoteringar för render cache and zoom performance
Använd dessa granskningsnoteringar för att säkerställa att funktionen har passerat demo-nivån och kan försvaras under leverans, support och kundeskalering.
- Beslut: cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state. Implementeringspresspunkt: reuse cached bitmaps only when the key fully matches the visible state. Acceptansbevis: time to first preview and time to final-quality render. Regressionsutlösare: rendering thumbnails and pages through separate caches wastes memory
- Beslut: memory budget, eviction strategy, thumbnail sharing, and prefetch distance. Implementeringspresspunkt: render low-latency placeholders before high-quality pages when appropriate. Acceptansbevis: eviction and prefetch behavior during continuous scrolling. Regressionsutlösare: large engineering drawings can exceed cache assumptions made for letters or invoices
- Beslut: progressive rendering behavior for fast preview versus final-quality output. Implementeringspresspunkt: cancel stale jobs and evict pages outside the viewport and prefetch window. Acceptansbevis: cache hit rate, render latency, queue depth, cancellation count, and memory peak. Regressionsutlösare: annotation overlays invalidate cached pages when review state changes
- Beslut: cancellation rules when users scroll, resize, search, or change zoom quickly. Implementeringspresspunkt: measure frame latency and memory during realistic scroll and zoom sequences. Acceptansbevis: viewport size, zoom level, DPI, page dimensions, and color-filter state. Regressionsutlösare: high-DPI displays multiply bitmap memory even when page count is small
- Beslut: cache key fields such as page, zoom, rotation, DPI, color mode, and annotation state. Implementeringspresspunkt: record render requests through one queue instead of direct control event handlers. Acceptansbevis: time to first preview and time to final-quality render. Regressionsutlösare: rendering thumbnails and pages through separate caches wastes memory
- Beslut: memory budget, eviction strategy, thumbnail sharing, and prefetch distance. Implementeringspresspunkt: reuse cached bitmaps only when the key fully matches the visible state. Acceptansbevis: eviction and prefetch behavior during continuous scrolling. Regressionsutlösare: large engineering drawings can exceed cache assumptions made for letters or invoices
- Beslut: progressive rendering behavior for fast preview versus final-quality output. Implementeringspresspunkt: render low-latency placeholders before high-quality pages when appropriate. Acceptansbevis: cache hit rate, render latency, queue depth, cancellation count, and memory peak. Regressionsutlösare: annotation overlays invalidate cached pages when review state changes
Gränsfall
- large engineering drawings can exceed cache assumptions made for letters or invoices
- annotation overlays invalidate cached pages when review state changes
- high-DPI displays multiply bitmap memory even when page count is small
- rendering thumbnails and pages through separate caches wastes memory
Delphi / C++Builder notes
PDFium Component should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. Important terms include render cache, zoom, DPI, progressive rendering, eviction, prefetch.
Delphi-kodexempel
Följande Delphi-skiss visar en praktisk servicegräns för detta ämne. Håll policykontroller, loggning och validering utanför det smala produktanropet så att arbetsflödet går att testa.
procedure TPreviewForm.RenderCachedPage(PageIndex: Integer; Zoom: Double);
var
CacheKey: string;
begin
CacheKey := Format('%d:%.2f', [PageIndex, Zoom]);
if not FRenderCache.TryGetValue(CacheKey, FPageBitmap) then
begin
FPageBitmap := PdfView.RenderPage(PageIndex, 0, Round(850 * Zoom), Round(1100 * Zoom), ro0, []);
FRenderCache.Add(CacheKey, FPageBitmap);
end;
PaintBitmap(FPageBitmap);
end;
Produktionschecklista
- Kör arbetsflödet på en tom fil, en normal kundfil och en värstafallfil
- Öppna den genererade PDF-filen med rätt visare, validator, skrivare eller nedströmsapplikation
- Logga produktversion, profilversion, inmatningshash, utdatasökväg, förfluten tid och antal varningar
- Håll lösenord, certifikat, tillfälliga filer och kunddata under tydliga lagringsregler
- Lägg till regressionsdokument när en kundfil avslöjar ett nytt gränsfall
Produktdokumentation
Fler kodexempel
procedure TViewerForm.RequestRender(TargetZoom: Single);
var
Status: TPdfProgressiveStatus;
begin
if FTokenSource <> nil then
FTokenSource.Cancel; // abandon the previous in-flight render
FTokenSource := TPdfCancellationTokenSource.New; // FPdfAsync unit
Status := Pdf.RenderPageProgressive(FBackBuffer, 0, 0,
FBackBuffer.Width, FBackBuffer.Height, FTokenSource.Token,
ro0, [reAnnotations]);
case Status of
prsDone: PresentBackBuffer;
prsCancelled: ; // superseded by a newer request: drop silently
prsFailed: ShowRenderFailure;
end;
end;