removePage method

Future<File?> removePage(
  1. int currentPage,
  2. File pdfFile
)

Removes the page at currentPage (1-based index) from the PDF.

Implementation

Future<File?> removePage(int currentPage, File pdfFile) async {
  PdfDocument? pdfDoc;
  try {
    pdfDoc = PdfDocument(inputBytes: await readFileInChunks(pdfFile));

    if (pdfDoc.pages.count > 1) {
      pdfDoc.pages.removeAt(currentPage - 1);
      return await saveFile(pdfDoc: pdfDoc, pdfFile: pdfFile);
    }
    return null;
  } finally {
    pdfDoc?.dispose();
  }
}