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 sharpnpm install sharpRasterize 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.





