Artykuł techniczny

PDFlibPas: scalanie i dzielenie dużych plików PDF z bezpośrednim dostępem

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 assembling statements, packets, evidence bundles, or page extracts from large customer PDFs. Traktuje large-PDF merge and split with direct access jako produkcyjną inżynierię dokumentów, a nie pojedyncze wywołanie komponentu.

Praktyczne ryzyko polega na tym, że merge and split tools often preserve pages but lose bookmarks, named destinations, metadata, page labels, or error evidence when files become large. Dlatego przepływ wymaga spisanego kontraktu, obserwowalnej diagnostyki i realistycznych plików regresyjnych.

Decyzje architektoniczne

Define what must follow the page. page-range syntax, validation behavior, and empty-range handling / bookmark, destination, page-label, annotation, and form preservation rules

  • page-range syntax, validation behavior, and empty-range handling
  • bookmark, destination, page-label, annotation, and form preservation rules
  • metadata ownership when multiple source documents are merged
  • temporary storage, rollback, progress, and cancellation policy for large files

Przebieg implementacji

Plan ranges and retained structures up front. Poniższa kolejność zachowuje czytelność przepływu pracy dla zespołów Delphi i C++Builder.

  1. validate all input files, page ranges, and output destinations before writing
  2. create a page mapping that records source file, source page, and output page
  3. copy or rebuild supporting structures according to the assembly profile
  4. write to a temporary output and validate the result before atomic replacement
  5. save the page map and warnings with the completed job

Dowody walidacji

Merge and split evidence for support. Zachowaj te pola wraz z wynikiem lub rekordem wsparcia.

  • input file list, hashes, sizes, page counts, selected ranges, and output page count
  • page map plus retained or dropped bookmark and destination counts
  • temporary path, cancellation point, rollback result, and elapsed time
  • warnings for damaged pages, unsupported structures, or signature implications

Pages are not the only content being moved

Large-document assembly should consider bookmarks, destinations, annotations, forms, attachments, metadata, page labels, and signatures. Direct access helps performance, but product policy decides which structures are preserved, rebuilt, or dropped.

Regression files worth keeping

Keep more than successful samples. A useful large-PDF merge and split with direct access regression set contains normal files, boundary files, and intentional failure files so the behavior is stable across releases.

  • signed source documents may lose signature trust when pages are extracted
  • bookmarks can point to pages that are removed or reordered
  • forms with shared field names can collide after merge
  • large output files need atomic replacement to avoid partial delivery
  • validate all input files, page ranges, and output destinations before writing
  • create a page mapping that records source file, source page, and output page

Notatki przeglądu inżynierskiego dla large-PDF merge and split with direct access

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: page-range syntax, validation behavior, and empty-range handling. Punkt nacisku implementacji: create a page mapping that records source file, source page, and output page. Dowody akceptacji: temporary path, cancellation point, rollback result, and elapsed time. Wyzwalacz regresji: large output files need atomic replacement to avoid partial delivery
  • Decyzja: bookmark, destination, page-label, annotation, and form preservation rules. Punkt nacisku implementacji: copy or rebuild supporting structures according to the assembly profile. Dowody akceptacji: warnings for damaged pages, unsupported structures, or signature implications. Wyzwalacz regresji: signed source documents may lose signature trust when pages are extracted
  • Decyzja: metadata ownership when multiple source documents are merged. Punkt nacisku implementacji: write to a temporary output and validate the result before atomic replacement. Dowody akceptacji: input file list, hashes, sizes, page counts, selected ranges, and output page count. Wyzwalacz regresji: bookmarks can point to pages that are removed or reordered
  • Decyzja: temporary storage, rollback, progress, and cancellation policy for large files. Punkt nacisku implementacji: save the page map and warnings with the completed job. Dowody akceptacji: page map plus retained or dropped bookmark and destination counts. Wyzwalacz regresji: forms with shared field names can collide after merge
  • Decyzja: page-range syntax, validation behavior, and empty-range handling. Punkt nacisku implementacji: validate all input files, page ranges, and output destinations before writing. Dowody akceptacji: temporary path, cancellation point, rollback result, and elapsed time. Wyzwalacz regresji: large output files need atomic replacement to avoid partial delivery
  • Decyzja: bookmark, destination, page-label, annotation, and form preservation rules. Punkt nacisku implementacji: create a page mapping that records source file, source page, and output page. Dowody akceptacji: warnings for damaged pages, unsupported structures, or signature implications. Wyzwalacz regresji: signed source documents may lose signature trust when pages are extracted
  • Decyzja: metadata ownership when multiple source documents are merged. Punkt nacisku implementacji: copy or rebuild supporting structures according to the assembly profile. Dowody akceptacji: input file list, hashes, sizes, page counts, selected ranges, and output page count. Wyzwalacz regresji: bookmarks can point to pages that are removed or reordered

Przypadki brzegowe

  • signed source documents may lose signature trust when pages are extracted
  • bookmarks can point to pages that are removed or reordered
  • forms with shared field names can collide after merge
  • large output files need atomic replacement to avoid partial delivery

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 merge, split, direct access, page range, bookmark, page map.

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 MergeLargePdfSet(const ListFile, OutputFile: string);
var
  Pdf: TPDFlib;
begin
  Pdf := TPDFlib.Create;
  try
    RequireSortedInputList(ListFile);
    Pdf.MergeFileListFast(ListFile, OutputFile);
    VerifyMergedPageRanges(OutputFile);
  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

PDFlibPas

Dodatkowe przykłady kodu

PageRef := Lib.DAFindPage(Handle, 250);          // page number -> object handle
if PageRef <> 0 then
begin
  Text := Lib.DAExtractPageText(Handle, PageRef, 0);
  Lib.DARenderPageToFile(Handle, PageRef, 5, 150, 'page250.png');
end;
Lib.AddToFileList('Statements', 'jan.pdf');
Lib.AddToFileList('Statements', 'feb.pdf');
Lib.AddToFileList('Statements', 'mar.pdf');
Lib.MergeFileList('Statements', 'q1-statements.pdf');

// Verify the result the cheap way: direct access again
Handle := Lib.DAOpenFileReadOnly('q1-statements.pdf', '');
Writeln('merged pages: ', Lib.DAGetPageCount(Handle));
Lib.DACloseFile(Handle);