PDF to PNG Red-Tint on macOS in IronPDF for Node.js

When rasterizing a PDF to PNG on macOS using IronPDF for Node.js, the output image has incorrect colors. A QR code that appears black in the source PDF renders red in the exported PNG.

A color-channel mapping error in the macOS PDF-to-image rasterization pipeline causes the output to use an incorrect channel order, producing the red tint.

Solution

Rasterize to JPG instead of PNG, then use sharp to convert the JPG to a grayscale PNG. This sidesteps the macOS color-channel mapping issue.

Install sharp:

npm install sharp
npm install sharp
SHELL

Rasterize to JPG, then convert to PNG:

import { PdfDocument, ImageType } from "@ironsoftware/ironpdf";
import sharp from "sharp";

const pdf = await PdfDocument.fromFile("input.pdf");

const [jpgPage] = await pdf.rasterizeToImageBuffers({
    fromPages: 0,
    imageType: ImageType.JPG,
});

const pngBuffer = await sharp(jpgPage)
    .flatten({ background: "#ffffff" })
    .grayscale()
    .threshold(160)
    .png()
    .toBuffer();

Adjust the threshold value between 120 and 200 based on the QR code contrast in your PDF. This post-processing step is safe for QR codes because they are binary: black cells on a white background. A grayscale conversion loses nothing for QR codes.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Version: 2026.5 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast?
run a sample watch your HTML become a PDF.