mergeFile method

Future<bool> mergeFile(
  1. String path
)

Implementation

Future<bool> mergeFile(String path) async {
  attach();
  final UPdfEdit? edit = _edit;
  final UPdfDocument? target = viewer.document;
  if (edit == null || target == null) return false;
  try {
    final UPdfDocument other = await UPdfDocument.open(path: path);
    final UPdfComposer composer = UPdfComposer();
    for (int i = 0; i < target.pageCount; i++) {
      await composer.addPage(target, i);
    }
    for (int i = 0; i < other.pageCount; i++) {
      await composer.addPage(other, i);
    }
    await other.close();
    final Uint8List bytes = composer.build(metadata: await target.metadata());
    await viewer.reopenWith(bytes);
    _edit = null;
    _undoStack.clear();
    attach();
    notifyListeners();
    return true;
  } on Object {
    return false;
  }
}