Get your API key
How to remove blank pages from a PDF (auto-detect, free)

How to remove blank pages from a PDF (auto-detect, free)

Remove blank pages from a PDF automatically. Detect and delete empty pages in your browser, with Python (pypdf), or Node.js (pdf-lib and pdf.js), no upload.

9 min read

Removing blank pages from a PDF means dropping pages that carry no text and no drawn content, then saving the rest as a smaller file. For a one-off, PDF4.dev's Delete pages tool lets you see thumbnails and remove empty pages in your browser. For repeatable cleanup, Python (pypdf) and Node.js (pdf-lib with pdf.js) can detect and delete blank pages automatically in a few lines, including the harder case of scanned documents.

Why PDFs end up with blank pages

Blank pages appear when a document is built or captured in a way that leaves empty sheets between real content. They waste paper on print, inflate file size, and break page counts in automated workflows.

Common sources of blank pages:

  • Double-sided scanning, where the back of a single-sided original scans as an empty page
  • Merging files that each end on an odd page, so a filler page separates chapters
  • Word or LibreOffice exports where a trailing paragraph pushes an empty final page
  • Reports generated from templates that render an empty section when data is missing
  • Fax or batch imports that pad each document to a fixed page count

The fix depends on how often you do it. A single document is fastest to clean by eye in a browser tool. A recurring export belongs in a script that detects empty pages every time without manual review.

Which method should you use?

The right method depends on the document type and whether you want automatic detection. A page can be "blank" in two different ways: an empty content stream (a page with no text or drawings) or a full-page white image (a blank scan). These need different detection strategies.

MethodAuto-detects blanksHandles scanned pagesBest forRuns where
PDF4.dev Delete pages toolManual, by thumbnailYes, visualOne-off cleanup, non-technical usersBrowser, no upload
Python (pypdf)Yes, text plus object checkNoDigital PDFs, batch scriptsLocal machine
Python (pixel scan)Yes, non-white ratioYesScanned or image-only PDFsLocal machine
Node.js (pdf.js plus pdf-lib)Yes, text plus operator checkPartialJavaScript pipelinesLocal or server
macOS PreviewManual, by thumbnailYes, visualQuick fixes on a MacDesktop app

Detection is a heuristic, not an exact rule. A page with only a faint watermark or a stray dot is technically not blank. Review the result of an automatic pass before deleting, and tune the threshold if pages are kept or dropped incorrectly.

For a single file, start with the browser tool. For anything recurring, jump to the code methods.

Remove blank pages in your browser (no upload, free)

PDF4.dev's Delete pages tool removes blank pages visually, with no software to install and no file leaving your device. It runs entirely in the browser using pdf-lib.

  1. Open the Delete pages tool and upload your PDF.
  2. Look at the page thumbnails and find the empty white pages.
  3. Click each blank page to mark it, then confirm the removal.
  4. Download the cleaned file. Remaining pages renumber on their own.

What this handles well:

  • Small to medium documents where you can eyeball the blanks
  • Scanned PDFs, because you see the rendered page, not just its text
  • Sensitive files, because nothing is uploaded to a server

What it does not handle:

  • Hundreds of pages where manual review is slow
  • Fully automated pipelines with no human in the loop

For those, use a script that detects empty pages on its own.

Remove blank pages in Python (pypdf)

For digital PDFs, pypdf detects blank pages by checking two things per page: whether any text can be extracted, and whether the page resources reference a drawn object (an /XObject such as an image or form). A page with neither is treated as blank and skipped.

from pypdf import PdfReader, PdfWriter
 
reader = PdfReader("input.pdf")
writer = PdfWriter()
 
for i, page in enumerate(reader.pages):
    text = (page.extract_text() or "").strip()
    resources = page.get("/Resources", {}) or {}
    has_objects = "/XObject" in resources
 
    if text or has_objects:
        writer.add_page(page)
    else:
        print(f"Removing blank page {i + 1}")
 
with open("output.pdf", "wb") as f:
    writer.write(f)

This keeps any page with body text or a drawn element and drops the rest. Install the library with pip install pypdf.

One limit: a page holding only a repeated header or footer counts as having text, so it is kept. If you want to drop near-empty boilerplate pages, require a minimum character count instead of any text at all, for example len(text) > 20. This handles the case where every page carries a page number but is otherwise empty.

Remove blank pages from a scanned PDF (pixel scan)

Scanned PDFs store each page as a full-page image, so the text-and-object check above keeps every page. To find blank pages in a scan, render each page to a bitmap and measure how much of it is non-white. Pages that are almost entirely white are the blank ones.

from pdf2image import convert_from_path
from pypdf import PdfReader, PdfWriter
import numpy as np
 
pages = convert_from_path("scanned.pdf", dpi=100)
keep = []
 
for i, image in enumerate(pages):
    gray = np.asarray(image.convert("L"))
    non_white_ratio = float(np.mean(gray < 245))
    if non_white_ratio > 0.005:
        keep.append(i)
    else:
        print(f"Blank scan page {i + 1}: {non_white_ratio:.4f}")
 
reader = PdfReader("scanned.pdf")
writer = PdfWriter()
for i in keep:
    writer.add_page(reader.pages[i])
 
with open("output.pdf", "wb") as f:
    writer.write(f)

The threshold 0.005 means a page is kept when more than half a percent of its pixels are darker than near-white. Raise it to ignore scanner speckle and dust; lower it to catch pages with only a faint mark. This needs pip install pdf2image pillow numpy plus the Poppler binaries that pdf2image uses to rasterize pages.

Remove blank pages in Node.js (pdf.js plus pdf-lib)

In a JavaScript pipeline, use pdf.js to inspect each page and pdf-lib to rebuild the file. pdf.js reads the text content and the operator list, so a page with no text and almost no drawing operations is treated as blank. pdf-lib then copies only the kept pages into a new document.

import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
import { PDFDocument } from "pdf-lib";
import { readFile, writeFile } from "node:fs/promises";
 
const bytes = await readFile("input.pdf");
const pdf = await getDocument({ data: new Uint8Array(bytes) }).promise;
 
const keep = [];
for (let n = 1; n <= pdf.numPages; n++) {
  const page = await pdf.getPage(n);
  const content = await page.getTextContent();
  const text = content.items.map((it) => it.str).join("").trim();
  const ops = await page.getOperatorList();
  const hasDrawings = ops.fnArray.length > 3;
 
  if (text || hasDrawings) keep.push(n - 1);
  else console.log(`Removing blank page ${n}`);
}
 
const src = await PDFDocument.load(bytes);
const out = await PDFDocument.create();
const copied = await out.copyPages(src, keep);
copied.forEach((p) => out.addPage(p));
await writeFile("output.pdf", await out.save());

Install both with npm install pdfjs-dist pdf-lib. The fnArray.length > 3 check treats a page with only setup operators as blank; adjust the number if pages with light content are dropped. For scanned PDFs, combine this with a pixel check like the Python example, since an image page always has drawing operators.

Remove blank pages on macOS with Preview

Preview, the built-in macOS PDF viewer, deletes blank pages without any third-party software. It works on any PDF, including scans, because you delete from rendered thumbnails.

  1. Open the PDF in Preview.
  2. Show the sidebar with View > Thumbnails (or ⌘ + ⌥ + 2).
  3. Click a blank page thumbnail. Hold to select several blank pages at once.
  4. Press Delete, or use Edit > Delete.
  5. Save with ⌘ + S.

Preview is fine for a few pages on a Mac. It has no automatic detection, so you still find the blanks by eye, and it can re-embed fonts inefficiently on save, which grows the file. For large or recurring jobs, use the browser tool or a script.

Remove blank pages from many PDFs at once

To clean a whole folder, wrap the detection logic in a loop. Read each PDF, drop the empty pages, and write the result to an output directory. This Python example reuses the digital-PDF check and processes every file in a folder.

from pathlib import Path
from pypdf import PdfReader, PdfWriter
 
src_dir = Path("input")
out_dir = Path("output")
out_dir.mkdir(exist_ok=True)
 
for pdf_path in src_dir.glob("*.pdf"):
    reader = PdfReader(str(pdf_path))
    writer = PdfWriter()
    removed = 0
 
    for page in reader.pages:
        text = (page.extract_text() or "").strip()
        has_objects = "/XObject" in (page.get("/Resources", {}) or {})
        if text or has_objects:
            writer.add_page(page)
        else:
            removed += 1
 
    with open(out_dir / pdf_path.name, "wb") as f:
        writer.write(f)
    print(f"{pdf_path.name}: removed {removed} blank pages")

Batch cleanup is where automatic detection pays off. Reviewing hundreds of files by hand is slow and error-prone, while a script applies the same rule to every document and reports what it removed.

Removing blank pages is one of several page operations you can run in the browser with no upload:

See the complete guide to PDF manipulation for the full set of page operations, or the delete pages guide and extract pages guide for the two operations that pair most often with blank-page removal.

Generate PDFs without blank pages in the first place

If a blank page keeps appearing in a document you generate yourself, the template is the real problem, not the output. A section that renders empty when its data is missing leaves a filler page every time. Fixing the template removes the cleanup step entirely.

With PDF4.dev's HTML-to-PDF API, you control which sections render per request, so an empty section produces no page at all.

// Only render the appendix when there is data for it
const response = await fetch("https://pdf4.dev/api/v1/render", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.PDF4_API_KEY}`,
  },
  body: JSON.stringify({
    template_id: "monthly-report",
    data: {
      showAppendix: appendixRows.length > 0,
      rows: appendixRows,
    },
  }),
});
 
const pdfBuffer = await response.arrayBuffer();

Conditional Handlebars blocks turn a section on or off per request, so a missing appendix or an empty final section never forces an extra sheet. The PDF arrives clean, with no post-processing pass to strip blank pages.

Free tools mentioned:

Delete Pdf PagesTry it freeSplit PdfTry it freeExtract PdfTry it freeCompress PdfTry it free

Start generating PDFs

Build PDF templates with a visual editor. Render them via API from any language in ~300ms.