Converting a PDF to grayscale replaces all color values with their luminance equivalents, producing a document that contains only shades of gray. This is useful for saving printer ink, reducing file size (30 to 60 percent smaller for image-heavy documents), and preparing files for black-and-white printing or archival. Use the PDF4.dev grayscale tool for a free browser-based conversion, or the code examples below for batch automation.
How grayscale conversion works
Grayscale conversion maps each RGB pixel to a single luminance value. The standard formula is ITU-R BT.601, used by Ghostscript, Photoshop, and most PDF processing libraries:
gray = 0.299 × R + 0.587 × G + 0.114 × B
Green receives the highest weight because the human eye is most sensitive to green light. The result is a perceptually accurate brightness value that preserves the visual contrast of the original.
There are two output modes:
| Mode | Color space | Bits per pixel | File size |
|---|---|---|---|
| True grayscale | DeviceGray | 8 | Smallest |
| Desaturated RGB | DeviceRGB (R=G=B) | 24 | 3x larger than true grayscale |
Ghostscript produces true DeviceGray output by default. Canvas-based approaches (pdfjs + pdf-lib, ImageMagick) produce desaturated RGB unless explicitly configured otherwise. Both look identical on screen, but true grayscale files are roughly one-third the size.
How to convert a PDF to grayscale online (free, no upload)
The PDF4.dev grayscale tool converts any PDF to grayscale entirely in your browser using pdfjs-dist and pdf-lib. Files never leave your device.
- Open pdf4.dev/tools/grayscale-pdf and drop your PDF onto the upload area.
- Choose the output quality (DPI). 150 DPI is a good default; use 300 DPI for print-quality output.
- Click Convert and wait for the processing to finish.
- Download the grayscale PDF. The result shows the original and new file sizes.
The tool renders each page to a canvas, desaturates every pixel using the luminance formula, then embeds the grayscale images into a new PDF document.
Grayscale PdfTry it freeHow to convert a PDF to grayscale with pdfjs + pdf-lib (Node.js)
This approach renders each page with pdfjs-dist, desaturates the canvas pixel data, then rebuilds the PDF with pdf-lib. It works in both Node.js and the browser.
npm install pdfjs-dist pdf-libimport { PDFDocument } from "pdf-lib";
import { getDocument, GlobalWorkerOptions } from "pdfjs-dist/legacy/build/pdf.mjs";
import { readFileSync, writeFileSync } from "fs";
// Node.js: disable worker threads
GlobalWorkerOptions.workerSrc = "";
async function pdfToGrayscale(
inputPath: string,
outputPath: string,
scale: number = 2 // 2x = ~150 DPI for A4
) {
const data = readFileSync(inputPath);
const pdfDoc = await getDocument({ data }).promise;
const outDoc = await PDFDocument.create();
for (let i = 1; i <= pdfDoc.numPages; i++) {
const page = await pdfDoc.getPage(i);
const viewport = page.getViewport({ scale });
// Create a canvas (use node-canvas or OffscreenCanvas)
const canvas = new OffscreenCanvas(viewport.width, viewport.height);
const ctx = canvas.getContext("2d")!;
await page.render({ canvasContext: ctx, viewport }).promise;
// Desaturate pixel data using BT.601 luminance
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pixels = imageData.data;
for (let j = 0; j < pixels.length; j += 4) {
const gray = 0.299 * pixels[j] + 0.587 * pixels[j + 1] + 0.114 * pixels[j + 2];
pixels[j] = gray; // R
pixels[j + 1] = gray; // G
pixels[j + 2] = gray; // B
// Alpha channel (j+3) stays unchanged
}
ctx.putImageData(imageData, 0, 0);
// Convert canvas to PNG and embed in the new PDF
const blob = await canvas.convertToBlob({ type: "image/png" });
const pngBytes = new Uint8Array(await blob.arrayBuffer());
const image = await outDoc.embedPng(pngBytes);
const newPage = outDoc.addPage([viewport.width / scale, viewport.height / scale]);
newPage.drawImage(image, {
x: 0,
y: 0,
width: viewport.width / scale,
height: viewport.height / scale,
});
}
const pdfBytes = await outDoc.save();
writeFileSync(outputPath, pdfBytes);
console.log(`Grayscale PDF saved to ${outputPath}`);
}
pdfToGrayscale("input.pdf", "grayscale.pdf");This approach rasterizes every page, so vector text becomes an image. The output quality depends entirely on the scale parameter: use 2 for screen viewing (150 DPI on A4) or 4 for print quality (300 DPI). Higher values produce larger files and take longer to process.
For a faster alternative that preserves vector text, use Ghostscript.
How to convert a PDF to grayscale with PyMuPDF (Python)
PyMuPDF renders each page to a grayscale pixmap using the built-in cs=pymupdf.csGRAY color space, then rebuilds the PDF from those pixmaps.
pip install pymupdfimport pymupdf # pip install pymupdf
def pdf_to_grayscale(input_path: str, output_path: str, dpi: int = 150) -> None:
src = pymupdf.open(input_path)
dst = pymupdf.open() # new empty PDF
for page in src:
# Render page as a grayscale pixmap (single channel)
pix = page.get_pixmap(dpi=dpi, colorspace=pymupdf.csGRAY)
# Create a new page with the original dimensions
new_page = dst.new_page(width=page.rect.width, height=page.rect.height)
# Insert the grayscale image into the new page
new_page.insert_image(new_page.rect, pixmap=pix)
dst.save(output_path, garbage=4, deflate=True)
dst.close()
src.close()
print(f"Grayscale PDF saved to {output_path}")
pdf_to_grayscale("input.pdf", "grayscale.pdf", dpi=150)PyMuPDF's csGRAY color space produces a true single-channel grayscale pixmap, so the output is smaller than desaturated RGB. Like the pdfjs approach above, this rasterizes vector text. Use 150 DPI for screen or 300 DPI for print.
Preserve vector text with PyMuPDF
To keep text as vectors while converting only images and fills to grayscale, iterate through page drawings and images individually instead of rasterizing the entire page. This is significantly more complex and only worth the effort for text-heavy documents where sharpness matters at any zoom level. For most use cases, Ghostscript (next section) is the better tool for vector-preserving grayscale.
How to convert a PDF to grayscale with Ghostscript (command line)
Ghostscript is the most reliable tool for grayscale conversion because it operates at the PDF color-space level, converting RGB, CMYK, and spot colors to DeviceGray without rasterizing text or vector graphics.
# Install on macOS
brew install ghostscript
# Install on Ubuntu/Debian
sudo apt install ghostscriptgs -sDEVICE=pdfwrite \
-dNOPAUSE \
-dBATCH \
-dSAFER \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-sOutputFile=grayscale.pdf \
input.pdfWhat each flag does:
| Flag | Effect |
|---|---|
-sColorConversionStrategy=Gray | Convert all color spaces to gray |
-dProcessColorModel=/DeviceGray | Set the output color model to single-channel gray |
-sDEVICE=pdfwrite | Output as a new PDF (not a raster image) |
-dSAFER | Restrict file operations for security |
This command converts all colors, including CMYK, ICC profiles, and named spot colors, into DeviceGray in a single pass. Text and vector paths stay as vectors. Embedded images are re-encoded in the gray color space, which reduces their size by roughly two-thirds compared to the RGB originals.
Fine-tune image quality
Add -dPDFSETTINGS to control how Ghostscript re-encodes embedded images:
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dPDFSETTINGS=/printer \
-sOutputFile=grayscale.pdf \
input.pdf| Setting | Resolution | Use case |
|---|---|---|
/screen | 72 DPI | Smallest file, screen viewing only |
/ebook | 150 DPI | Good balance for most documents |
/printer | 300 DPI | Print-quality output |
/prepress | 300 DPI, color preserved | Not useful here (overrides Gray) |
For most documents, /ebook or /printer produces the right balance between quality and file size.
Batch conversion with Ghostscript
mkdir -p grayscale
for f in *.pdf; do
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dPDFSETTINGS=/ebook \
-sOutputFile="grayscale/$f" \
"$f"
doneHow to convert a PDF to grayscale with ImageMagick (command line)
ImageMagick converts PDFs by rasterizing each page and re-encoding it. It delegates PDF reading to Ghostscript internally, so Ghostscript must be installed alongside it.
# Install on macOS
brew install imagemagick ghostscript
# Install on Ubuntu/Debian
sudo apt install imagemagick ghostscriptconvert -colorspace Gray -density 150 input.pdf grayscale.pdfOr with ImageMagick 7:
magick -density 150 input.pdf -colorspace Gray grayscale.pdfThe -density 150 flag sets the rasterization resolution. Like the canvas-based approaches, ImageMagick rasterizes all pages, so vector text becomes an image. For large documents, this is slower than Ghostscript's native color-space conversion and produces larger files.
ImageMagick is most useful when you need additional image processing in the same pipeline, such as adjusting contrast or sharpening after desaturation:
magick -density 200 input.pdf \
-colorspace Gray \
-contrast-stretch 2%x1% \
-sharpen 0x1 \
grayscale.pdfGrayscale conversion methods compared
| Method | Preserves vectors | True DeviceGray | Speed | File size reduction | Best for |
|---|---|---|---|---|---|
| PDF4.dev tool | No | No (desaturated RGB) | Fast | 30-50% | Quick one-off, no install |
| pdfjs + pdf-lib (Node.js) | No | No (desaturated RGB) | Moderate | 30-50% | Browser or Node.js apps |
| PyMuPDF (Python) | No | Yes | Fast | 40-60% | Python automation |
| Ghostscript | Yes | Yes | Fast | 40-60% | Best quality, batch scripts |
| ImageMagick | No | Depends on config | Slow | 30-50% | Image post-processing |
Ghostscript is the best choice for production pipelines because it preserves vector text, produces true DeviceGray output, and handles all PDF color spaces (RGB, CMYK, spot colors, ICC profiles) in a single pass. The canvas-based methods (pdfjs, PyMuPDF, ImageMagick) are simpler to set up but rasterize the entire page, which affects text sharpness at low resolutions.
Common use cases for grayscale PDFs
Saving printer ink and toner. Color ink costs 5 to 10 times more per page than black toner (Keypoint Intelligence, 2024). Converting internal documents, drafts, and reference materials to grayscale before printing reduces consumable costs without losing readability.
Reducing file size for storage and email. A grayscale PDF with image-heavy content is typically 30 to 60 percent smaller than the color original because each pixel stores 8 bits instead of 24 (RGB) or 32 (CMYK). For documents going into long-term storage or email attachments with size limits, this reduction adds up. Combine grayscale with compression for maximum reduction.
Print preparation for B&W printers. Sending a color PDF to a black-and-white printer lets the printer driver handle the color conversion, which varies between models and can produce washed-out results. Pre-converting to grayscale gives you control over the luminance mapping and guarantees consistent output across printers.
Document archiving. Archival standards like PDF/A (ISO 19005) do not require grayscale, but many archival workflows convert to grayscale to reduce storage costs and standardize the appearance of documents from multiple sources.
Creating visual consistency for mixed-source documents. When merging PDFs from different authors, departments, or scanners, color profiles vary. Converting everything to grayscale before merging produces a uniform document where no page looks out of place.
Summary
- Grayscale conversion replaces color values with luminance equivalents, typically reducing file size by 30 to 60 percent for image-heavy PDFs.
- For a quick conversion with no install, use the PDF4.dev grayscale tool, which runs entirely in your browser.
- For the best quality with preserved vector text, use Ghostscript with
-sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray. - For Python automation, PyMuPDF renders pages to true grayscale pixmaps with
cs=pymupdf.csGRAY. - For Node.js or browser apps, pdfjs-dist + pdf-lib render to canvas and desaturate pixel data.
- ImageMagick works but rasterizes every page and is slower than Ghostscript for pure grayscale conversion.
- True DeviceGray output (Ghostscript, PyMuPDF) produces files roughly one-third the size of desaturated RGB output (pdfjs, ImageMagick).
Start generating PDFs
Build PDF templates with a visual editor. Render them via API from any language in ~300ms.


