Artykuł techniczny

PDFium: Lazarus and Free Pascal viewer integration in Delphi

Integruj workflow PDFium VCL Component w aplikacjach Delphi i C++Builder albo workflow PDFium LCL Component w Lazarus/FPC, z komponentami źródłowymi do podglądu, renderowania, formularzy, drukowania, raportów preflight i walidacji zgodnej ze standardami.

Ten artykuł jest przeznaczony dla teams sharing PDF viewing code between Delphi, Lazarus, and Free Pascal applications. Traktuje Lazarus and Free Pascal viewer integration jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.

Praktyczne ryzyko polega na tym, że a viewer can compile in multiple IDEs yet fail in deployment because widget-set behavior, binary loading, calling conventions, and resource paths differ. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.

Decyzje architektoniczne

Treat the viewer layer as portable infrastructure. supported IDEs, compiler versions, CPU architectures, and widget sets / PDFium binary location, bitness, load failure message, and update policy

  • supported IDEs, compiler versions, CPU architectures, and widget sets
  • PDFium binary location, bitness, load failure message, and update policy
  • high-DPI scaling, mouse wheel, keyboard, and focus behavior across frameworks
  • feature parity expectations for thumbnails, search, forms, printing, and annotations

Przebieg implementacji

Stabilize runtime loading before adding UI features. Poniższa kolejność zachowuje czytelność przepływu pracy dla zespołów Delphi i C++Builder.

  1. create a small viewer shell that loads the PDFium runtime before opening documents
  2. normalize paths and binary names for each supported deployment layout
  3. exercise zoom, scroll, selection, and focus events on every widget set
  4. separate shared PDF logic from framework-specific panels and dialogs
  5. package diagnostics that identify missing binaries and architecture mismatches

Dowody walidacji

Deployment evidence for mixed-toolchain support. Zachowaj te pola wraz z wynikiem lub rekordem wsparcia.

  • compiler, widget set, target architecture, PDFium binary path, and runtime version
  • load success or failure reason before the first document is opened
  • input-event test results for wheel, drag, keyboard, focus, and high-DPI scaling
  • feature matrix showing which viewer actions are supported in each build

Portability is a packaging decision

A Lazarus and FPC integration should define how the PDFium binary is found, which widget sets are supported, how DPI and input events are normalized, and which viewer features are guaranteed across platforms.

Operational metrics to watch

The first release should expose enough metrics to prove the workflow is healthy under real files, not only under curated samples.

  • count and rate for compiler, widget set, target architecture, PDFium binary path, and runtime version
  • warning trend for a 32-bit application cannot load a 64-bit PDFium binary
  • latency of the stage that must create a small viewer shell that loads the PDFium runtime before opening documents
  • profile usage for supported IDEs, compiler versions, CPU architectures, and widget sets

Notatki przeglądu inżynierskiego dla Lazarus and Free Pascal viewer integration

Użyj tych notatek przeglądu, aby upewnić się, że funkcja wyszła poza demonstrację i da się ją obronić podczas wydania, wsparcia i eskalacji klienta.

  • Decyzja: supported IDEs, compiler versions, CPU architectures, and widget sets. Punkt nacisku implementacji: normalize paths and binary names for each supported deployment layout. Dowody akceptacji: input-event test results for wheel, drag, keyboard, focus, and high-DPI scaling. Wyzwalacz regresji: printing and file dialogs may need framework-specific wrappers
  • Decyzja: PDFium binary location, bitness, load failure message, and update policy. Punkt nacisku implementacji: exercise zoom, scroll, selection, and focus events on every widget set. Dowody akceptacji: feature matrix showing which viewer actions are supported in each build. Wyzwalacz regresji: a 32-bit application cannot load a 64-bit PDFium binary
  • Decyzja: high-DPI scaling, mouse wheel, keyboard, and focus behavior across frameworks. Punkt nacisku implementacji: separate shared PDF logic from framework-specific panels and dialogs. Dowody akceptacji: compiler, widget set, target architecture, PDFium binary path, and runtime version. Wyzwalacz regresji: relative paths often work in the IDE and fail from installed shortcuts

Przypadki brzegowe

  • a 32-bit application cannot load a 64-bit PDFium binary
  • relative paths often work in the IDE and fail from installed shortcuts
  • widget-set differences can alter focus behavior in docked panes
  • printing and file dialogs may need framework-specific wrappers

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 Lazarus, Free Pascal, LCL, PDFium, widget set, runtime loading.

Przykład kodu Delphi

Poniższy szkic Delphi pokazuje praktyczną granicę usługi dla tego tematu. Kontrole zasad, logowanie i walidację trzymaj poza wąskim blokiem wywołań produktu, aby przepływ pozostał testowalny.

procedure TMainForm.OpenDocument(const FileName: string);
begin
  PdfView.LoadFromFile(FileName);
  TrackDocumentLifetime(FileName, PdfView.PageCount);
  PageSpinEdit.MaxValue := PdfView.PageCount;
  RenderCurrentPage;
  UpdateToolbarState;
end;

Lista produkcyjna

  • Uruchom przepływ pracy na pustym pliku, zwykłym pliku klienta i pliku z najgorszego scenariusza
  • Otwórz wygenerowany plik PDF w docelowej przeglądarce, walidatorze, drukarce lub aplikacji nadrzędnej
  • Zaloguj wersję produktu, wersję profilu, hash wejścia, ścieżkę wyjścia, czas wykonania i liczbę ostrzeżeń
  • Przechowuj hasła, certyfikaty, pliki tymczasowe i dane klienta zgodnie z jednoznacznymi zasadami retencji
  • Dodaj dokument regresyjny, gdy plik klienta ujawni nowy przypadek brzegowy

Dokumentacja produktu

PDFium Component

Dodatkowe przykłady kodu

procedure TViewerForm.FormCreate(Sender: TObject);
begin
  Pdf := TPdf.Create(Self);

  PdfView := TPdfView.Create(Self);
  PdfView.Parent := Self;
  PdfView.Align := alClient;
  PdfView.Pdf := Pdf;
  PdfView.FitMode := pfmFitWidth;

  if ParamCount > 0 then
  begin
    Pdf.FileName := ParamStr(1);
    Pdf.Active := True;   // opens the document; PageCount valid after this
  end;
end;