losLab PDF Library zapewnia zespołom Delphi i C++Builder silnik PDF z dostępnym kodem źródłowym dla przepływów desktopowych, serwerowych, DLL, ActiveX i Dylib, z wbudowanymi kontrolami PDF/A i PDF/UA, podpisami PAdES oraz wyborem renderera bez wysyłania dokumentów do zewnętrznej usługi PDF.
Ten artykuł jest przeznaczony dla teams building print-preview, hard-copy approval, label, or controlled-output workflows in Delphi. Traktuje print preview and device-context output jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.
Praktyczne ryzyko polega na tym, że print output can differ from preview when device margins, scaling, rotation, duplex settings, and driver behavior are not modeled explicitly. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.
Decyzje architektoniczne
Separate PDF page geometry from printer geometry. fit, actual size, shrink-only, center, rotation, and crop rules / paper selection, printable margins, tray, duplex, and color mode policy
- fit, actual size, shrink-only, center, rotation, and crop rules
- paper selection, printable margins, tray, duplex, and color mode policy
- preview fidelity requirements compared with printer-driver output
- whether annotations, form fields, watermarks, and backgrounds are printed
Przebieg implementacji
Preview with the same print contract used for output. Poniższa kolejność zachowuje czytelność przepływu pracy dla zespołów Delphi i C++Builder.
- read page size and rotation before asking the printer for device capabilities
- compute the target rectangle from paper, printable area, and scaling policy
- render preview using the same geometry contract as the print job
- record driver and device context details when output is generated
- test high-value documents on the printer families customers actually use
Dowody walidacji
Print evidence that helps support reproduce issues. Zachowaj te pola wraz z wynikiem lub rekordem wsparcia.
- printer name, driver version, paper size, printable area, scaling, and rotation
- PDF page box, page number, rendered rectangle, and DPI
- annotation and form-field print policy
- operator selection and print result or driver error
A device context is a target, not a neutral canvas
A production print workflow should know the PDF page box, target paper size, printable area, scaling rule, rotation decision, and driver settings before rendering to a device context.
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 printer name, driver version, paper size, printable area, scaling, and rotation
- warning trend for printer drivers can change printable margins after paper selection
- latency of the stage that must read page size and rotation before asking the printer for device capabilities
- profile usage for fit, actual size, shrink-only, center, rotation, and crop rules
Notatki przeglądu inżynierskiego dla print preview and device-context output
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: fit, actual size, shrink-only, center, rotation, and crop rules. Punkt nacisku implementacji: compute the target rectangle from paper, printable area, and scaling policy. Dowody akceptacji: annotation and form-field print policy. Wyzwalacz regresji: preview should disclose when it cannot match a driver-specific feature
- Decyzja: paper selection, printable margins, tray, duplex, and color mode policy. Punkt nacisku implementacji: render preview using the same geometry contract as the print job. Dowody akceptacji: operator selection and print result or driver error. Wyzwalacz regresji: printer drivers can change printable margins after paper selection
- Decyzja: preview fidelity requirements compared with printer-driver output. Punkt nacisku implementacji: record driver and device context details when output is generated. Dowody akceptacji: printer name, driver version, paper size, printable area, scaling, and rotation. Wyzwalacz regresji: landscape pages need a clear auto-rotation policy
- Decyzja: whether annotations, form fields, watermarks, and backgrounds are printed. Punkt nacisku implementacji: test high-value documents on the printer families customers actually use. Dowody akceptacji: PDF page box, page number, rendered rectangle, and DPI. Wyzwalacz regresji: duplex output can expose odd-page and blank-page assumptions
- Decyzja: fit, actual size, shrink-only, center, rotation, and crop rules. Punkt nacisku implementacji: read page size and rotation before asking the printer for device capabilities. Dowody akceptacji: annotation and form-field print policy. Wyzwalacz regresji: preview should disclose when it cannot match a driver-specific feature
Przypadki brzegowe
- printer drivers can change printable margins after paper selection
- landscape pages need a clear auto-rotation policy
- duplex output can expose odd-page and blank-page assumptions
- preview should disclose when it cannot match a driver-specific feature
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 device context, print preview, DPI, printable area, scaling, duplex.
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 PaintPreviewPage(Canvas: TCanvas; const FileName: string; PageRef: Integer; Dpi: Double);
var
Pdf: TPDFlib;
FileHandle: Integer;
begin
Pdf := TPDFlib.Create;
try
FileHandle := Pdf.DAOpenFileReadOnly(FileName, '');
try
Pdf.DARenderPageToDC(FileHandle, PageRef, Dpi, Canvas.Handle);
DrawPreviewOverlay(Canvas, PageRef, Dpi);
finally
Pdf.DACloseFile(FileHandle);
end;
finally
Pdf.Free;
end;
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
Dodatkowe przykłady kodu
var
Pdf: TPDFlib;
Virt: WideString;
Opt: Integer;
begin
Pdf := TPDFlib.Create;
try
if Pdf.LoadFromFile('report.pdf', '') <> 1 then
raise Exception.Create('load failed');
Virt := Pdf.NewCustomPrinter(Pdf.GetDefaultPrinterName);
Pdf.SetupPrinter(Virt, 1, 9); // setting 1 = paper, DMPAPER_A4
Pdf.SetupPrinter(Virt, 11, 1); // setting 11 = orientation, 1 = portrait
Opt := Pdf.PrintOptions(1, 1, 'Monthly Report'); // fit to paper, auto-rotate + center
Pdf.PrintDocument(Virt, 1, Pdf.PageCount, Opt);
finally
Pdf.Free;
end;
end;procedure ShowPrinterTruePreview(Pdf: TPDFlib; const Virt: WideString; Opt: Integer);
var
Data: AnsiString;
Strm: TMemoryStream;
Bmp: TBitmap;
begin
Data := Pdf.GetPrintPreviewBitmapToString(Virt, 1, Opt, 1200, 0);
Strm := TMemoryStream.Create;
try
Strm.WriteBuffer(PAnsiChar(Data)^, Length(Data));
Strm.Position := 0;
Bmp := TBitmap.Create;
try
Bmp.LoadFromStream(Strm);
PreviewImage.Picture.Assign(Bmp);
finally
Bmp.Free;
end;
finally
Strm.Free;
end;
end;