Artykuł techniczny

PDFium Component: secure PDF preview surfaces 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 showing sensitive PDFs inside line-of-business applications without granting full document-control features. Traktuje secure PDF preview surfaces jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.

Praktyczne ryzyko polega na tym, że a preview window can accidentally become a data-exfiltration surface if printing, saving, clipboard, links, attachments, and temporary files are not governed. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.

Decyzje architektoniczne

Treat preview as a permissioned operation. which roles can open, print, save, copy, search, annotate, or follow links / temporary file location, lifetime, naming, encryption, and cleanup policy

  • which roles can open, print, save, copy, search, annotate, or follow links
  • temporary file location, lifetime, naming, encryption, and cleanup policy
  • external link, embedded file, JavaScript, and attachment handling
  • audit events required for open, close, denied action, print, and export attempts

Przebieg implementacji

Disable features by policy rather than hiding buttons. Poniższa kolejność zachowuje czytelność przepływu pracy dla zespołów Delphi i C++Builder.

  1. resolve the user's preview policy before the PDF is loaded
  2. open the document through a controlled stream or temporary file boundary
  3. disable and audit denied actions at the command layer, not only in visible buttons
  4. handle links, attachments, and scripts according to the preview profile
  5. clean temporary resources and write a session summary when the viewer closes

Dowody walidacji

Security evidence for preview sessions. Zachowaj te pola wraz z wynikiem lub rekordem wsparcia.

  • user role, document classification, preview profile, and allowed action list
  • denied commands, external target attempts, attachment attempts, and print requests
  • temporary file path or stream mode plus cleanup result
  • session duration, pages viewed when policy requires it, and close reason

Read-only UI is not the same as secure preview

Secure preview combines viewer permissions, application roles, document policy, link handling, attachment policy, temp-file control, and audit logging. The PDF renderer is only one layer of that surface.

Zachowanie widoczne dla klienta

Użytkownicy nie widzą wewnętrznej kolejności wywołań. Widzą, czy plik się otwiera, przechodzi walidację, drukuje się, edytuje, importuje lub zostaje odrzucony. The workflow should translate secure PDF preview surfaces results into states users can act on.

  • resolve the user's preview policy before the PDF is loaded
  • open the document through a controlled stream or temporary file boundary
  • disable and audit denied actions at the command layer, not only in visible buttons
  • keyboard shortcuts and context menus can bypass toolbar-only restrictions
  • attachments and links may leak data even when save is disabled

Notatki przeglądu inżynierskiego dla secure PDF preview surfaces

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: which roles can open, print, save, copy, search, annotate, or follow links. Punkt nacisku implementacji: open the document through a controlled stream or temporary file boundary. Dowody akceptacji: temporary file path or stream mode plus cleanup result. Wyzwalacz regresji: watermarks should supplement policy but should not be the only protection
  • Decyzja: temporary file location, lifetime, naming, encryption, and cleanup policy. Punkt nacisku implementacji: disable and audit denied actions at the command layer, not only in visible buttons. Dowody akceptacji: session duration, pages viewed when policy requires it, and close reason. Wyzwalacz regresji: keyboard shortcuts and context menus can bypass toolbar-only restrictions

Przypadki brzegowe

  • keyboard shortcuts and context menus can bypass toolbar-only restrictions
  • attachments and links may leak data even when save is disabled
  • temporary preview files can remain recoverable if cleanup is not verified
  • watermarks should supplement policy but should not be the only protection

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 secure preview, read-only viewer, audit log, temporary file, attachments, policy.

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 TSecurePreview.OpenReadOnly(const FileName: string);
begin
  RequireAllowedLocation(FileName);
  PdfView.LoadFromFile(FileName);
  DisableSaveAndClipboardCommands;
  RenderWatermarkedPage(1, CurrentUserName);
  LogPreviewSession(FileName, PdfView.PageCount);
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 TPreviewPane.PdfViewWebLinkClick(Sender: TObject;
  const Url: WString; var Handled: Boolean);
begin
  Handled := True;   // never fall through to the default shell behavior

  if (AnsiStartsText('https://', Url) or AnsiStartsText('http://', Url))
    and HostIsAllowed(Url) then
    OpenInBrowser(Url)
  else
    FAudit.LogBlockedLink(FDocumentId, Url);
end;
procedure TPreviewPane.ExportAttachment(Index: Integer; const TargetDir: string);
var
  RawName, SafeName, Ext: string;
  Data: TBytes;
begin
  RawName := string(Pdf.AttachmentName[Index]);
  SafeName := ExtractFileName(RawName);    // strips any path components
  Ext := LowerCase(ExtractFileExt(SafeName));

  if not FAllowedExt.Contains(Ext) then    // allowlist, not blocklist
    raise EPreviewPolicy.CreateFmt('Attachment type %s blocked by policy', [Ext]);

  Data := Pdf.Attachment[Index];           // embedded payload as raw bytes
  TFile.WriteAllBytes(
    IncludeTrailingPathDelimiter(TargetDir) + SafeName, Data);
end;