Teknik makale

PDFlibPas: multi-engine PDF rendering in Delphi

losLab PDF Library, Delphi ve C++Builder ekiplerine masaüstü, sunucu, DLL, ActiveX ve Dylib iş akışları için kaynak kodlu bir PDF motoru sağlar; dahili PDF/A ve PDF/UA kontrolleri, PAdES imzalama ve belgeleri harici PDF servisine göndermeden renderer seçimi sunar.

Bu yazı developers who need preview, printing, raster export, or fallback rendering across different document types için hazırlanmıştır. multi-engine PDF rendering konusunu tek bir bileşen çağrısı olarak değil, üretim düzeyinde belge mühendisliği olarak ele alır.

Pratik risk şudur: multiple rendering engines can improve coverage, but without a selection policy they create inconsistent output and support disputes. Bu nedenle akışın yazılı sözleşmeye, gözlemlenebilir tanılara ve gerçekçi regresyon dosyalarına ihtiyacı vardır.

Mimari kararlar

Choose the renderer for a documented reason. primary and fallback engines for preview, print, thumbnail, and image export / DPI, antialiasing, color management, transparency, and annotation policy

  • primary and fallback engines for preview, print, thumbnail, and image export
  • DPI, antialiasing, color management, transparency, and annotation policy
  • how to compare engine output for support and regression testing
  • what to do when an engine fails on a damaged or unsupported page

Uygulama akışı

Normalize rendering options across engines. Aşağıdaki sıra, iş akışını Delphi ve C++Builder ekipleri için incelenebilir tutar.

  1. select an engine based on operation type and document capability checks
  2. normalize page size, rotation, DPI, and annotation visibility before rendering
  3. capture engine-specific warnings and fallback reasons
  4. compare critical pages against reference images when output quality matters
  5. include renderer details in logs and support bundles

Doğrulama kanıtı

Rendering evidence that explains differences. Bu alanları çıktı veya destek kaydıyla birlikte saklayın.

  • engine name, version, operation type, page number, DPI, and render options
  • fallback reason, warnings, and page features that influenced selection
  • visual comparison metrics or reference-image approval for critical workflows
  • output dimensions, color mode, and elapsed render time

Fallback rendering should be visible

A multi-engine renderer should not silently switch behavior. The application should expose which engine rendered each page, why a fallback happened, and which options controlled DPI, annotations, transparency, and color.

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.

  • primary and fallback engines for preview, print, thumbnail, and image export
  • DPI, antialiasing, color management, transparency, and annotation policy
  • how to compare engine output for support and regression testing
  • what to do when an engine fails on a damaged or unsupported page
  • engine name, version, operation type, page number, DPI, and render options
  • fallback reason, warnings, and page features that influenced selection

Mühendislik inceleme notları: multi-engine PDF rendering

Özelliğin bir demoyu aşıp sürüm, destek ve müşteri eskalasyonu sırasında savunulabilir olduğunu doğrulamak için bu inceleme notlarını kullanın.

  • Karar: primary and fallback engines for preview, print, thumbnail, and image export. Uygulama baskı noktası: normalize page size, rotation, DPI, and annotation visibility before rendering. Kabul kanıtı: visual comparison metrics or reference-image approval for critical workflows. Regresyon tetikleyicisi: visual differences need classification as acceptable, warning, or defect
  • Karar: DPI, antialiasing, color management, transparency, and annotation policy. Uygulama baskı noktası: capture engine-specific warnings and fallback reasons. Kabul kanıtı: output dimensions, color mode, and elapsed render time. Regresyon tetikleyicisi: annotations may render differently depending on engine and options

Sınır durumları

  • annotations may render differently depending on engine and options
  • transparency and overprint behavior can affect print workflows
  • engine fallback should not bypass security or permission policy
  • visual differences need classification as acceptable, warning, or defect

Delphi / C++Builder notes

PDFlibPas 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 rendering engine, DPI, thumbnail, print preview, fallback, visual comparison.

Delphi kod örneği

Aşağıdaki Delphi taslağı bu konu için pratik bir servis sınırını gösterir. Politika kontrollerini, günlüklemeyi ve doğrulamayı dar ürün çağrısı bölümünün dışında tutarak akışı test edilebilir bırakın.

procedure RenderWithFallback(const InputFile, OutputPng: string; PageRef: Integer);
var
  Pdf: TPDFlib;
  FileHandle: Integer;
begin
  Pdf := TPDFlib.Create;
  try
    FileHandle := Pdf.DAOpenFileReadOnly(InputFile, '');
    try
      if Pdf.DARenderPageToFile(FileHandle, PageRef, 5, 300, OutputPng) <> 1 then
        RenderWithSecondaryEngine(InputFile, OutputPng, PageRef, Pdf.LastRenderError);
    finally
      Pdf.DACloseFile(FileHandle);
    end;
  finally
    Pdf.Free;
  end;
end;

Üretim kontrol listesi

  • İş akışını boş bir dosyada, normal bir müşteri dosyasında ve en kötü durum dosyasında çalıştırın
  • Oluşturulan PDF'yi hedef görüntüleyici, doğrulayıcı, yazıcı veya aşağı akış uygulamasıyla açın
  • Ürün sürümünü, profil sürümünü, giriş karmasını, çıktı yolunu, geçen süreyi ve uyarı sayısını kaydedin
  • Parolaları, sertifikaları, geçici dosyaları ve müşteri verilerini açık saklama kuralları altında tutun
  • Bir müşteri dosyası yeni bir uç durum ortaya çıkardığında regresyon belgeleri ekleyin

Ürün belgeleri

PDFlibPas

Ek kod örnekleri

PDF.SetRenderScale(2.0);                    // every later render is doubled
PDF.RenderPageToFile(150, 1, 5, 'p1.png');  // effectively 300 DPI
PDF.SetRenderScale(1.0);                    // reset, or your thumbnails arrive huge
procedure RenderPageWithFallback(PDF: TPDFlib; Page: Integer; const OutFile: string);
begin
  PDF.SelectRenderer(1);                            // built-in first
  PDF.RenderPageToFile(200, Page, 5, OutFile);      // 5 = PNG
  if PDF.LastRenderError = '' then Exit;
  LogEngineFailure('built-in', Page, PDF.LastRenderError);
  if PDF.SelectRenderer(3) = 3 then                 // PDFium as the heavy fallback
  begin
    PDF.RenderPageToFile(200, Page, 5, OutFile);
    if PDF.LastRenderError = '' then Exit;
    LogEngineFailure('pdfium', Page, PDF.LastRenderError);
  end;
  raise Exception.CreateFmt('Page %d failed on all available engines', [Page]);
end;