merge static method

Future<Uint8List> merge(
  1. List<Uint8List> documents, {
  2. PdfMergeOptions? options,
  3. bool compress = true,
  4. bool verbose = false,
  5. PdfVersion version = PdfVersion.pdf_1_5,
  6. DeflateCallback? deflate,
  7. bool useIsolate = false,
})

Merges several PDFs into a new document.

final bytes = await PdfDocument.merge(<Uint8List>[docA, docB]);

Each entry is read by a PdfDocumentParser with repair enabled, so that a file with a damaged cross-reference table can still be merged. Encrypted documents are not supported and result in PdfMergeException.

Merging invalidates any existing digital signature: it covers the exact bytes of the document it was applied to. See PdfMergeOptions for the three keys that control the outcome, and PdfDocumentMerger.warnings — reachable through the non-static API — for the report of what was lost.

Implementation

static Future<Uint8List> merge(
  List<Uint8List> documents, {
  PdfMergeOptions? options,
  bool compress = true,
  bool verbose = false,
  PdfVersion version = PdfVersion.pdf_1_5,
  DeflateCallback? deflate,
  bool useIsolate = false,
}) async {
  final document = PdfDocument(
    compress: compress,
    verbose: verbose,
    version: version,
    deflate: deflate,
  );
  final merger = PdfDocumentMerger(document, options: options);

  for (var index = 0; index < documents.length; index++) {
    final parser = PdfDocumentParser(documents[index], allowRepair: true);
    merger.append(parser, label: 'documento ${index + 1}');
  }
  merger.finish();

  return document.save(useIsolate: useIsolate);
}