Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix garbled text copying in Chrome/Edge for PDFs with >256 unique characters (#1659)
- Fix Link accessibility issues
- Fix Table Accessibility Issue: Operator CS/cs not allowed in this current state
- Fix Interlaced PNG with indexed transparency rendered incorrectly
- Preserve existing PageMode instead of overwriting when adding outlines

### [v0.17.2] - 2025-08-30
Expand Down
6 changes: 6 additions & 0 deletions lib/image/png.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class PNGImage {

loadIndexedAlphaChannel() {
const transparency = this.image.transparency.indexed;
const isInterlaced = this.image.interlaceMethod === 1;
return this.image.decodePixels((pixels) => {
const alphaChannel = Buffer.alloc(this.width * this.height);

Expand All @@ -158,6 +159,11 @@ class PNGImage {
alphaChannel[i++] = transparency[pixels[j]];
}

// For interlaced images, re-encode the decoded pixel data
if (isInterlaced) {
this.imgData = zlib.deflateSync(Buffer.from(pixels));
}

this.alphaChannel = zlib.deflateSync(alphaChannel);
return this.finalize();
});
Expand Down
Binary file added tests/images/issue-414-interlaced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions tests/visual/interlaced-png.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { runDocTest } from './helpers';

describe('interlaced PNG (Adam7)', function () {
test('interlaced grayscale renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Interlaced Grayscale PNG (Adam7)', 50, 30);
doc.image('tests/images/interlaced-grayscale-8bit.png', 50, 50, {
width: 100,
});
});
});

test('interlaced RGB renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Interlaced RGB PNG (Adam7)', 50, 30);
doc.image('tests/images/interlaced-rgb-8bit.png', 50, 50, {
width: 100,
});
});
});

test('interlaced RGB 16bit renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Interlaced RGB 16-bit PNG (Adam7)', 50, 30);
doc.image('tests/images/interlaced-rgb-16bit.png', 50, 50, {
width: 100,
});
});
});

test('interlaced palette renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Interlaced Palette PNG (Adam7)', 50, 30);
doc.image('tests/images/interlaced-pallete-8bit.png', 50, 50, {
width: 100,
});
});
});

test('interlaced RGBA renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Interlaced RGBA PNG (Adam7)', 50, 30);
doc.image('tests/images/interlaced-rgb-alpha-8bit.png', 50, 50, {
width: 100,
});
});
});

// https://github.com/foliojs/pdfkit/issues/414
test('issue #414 - interlaced palette PNG renders correctly', function () {
return runDocTest(function (doc) {
doc.font('tests/fonts/Roboto-Regular.ttf');
doc.fontSize(12);

doc.text('Issue #414: Interlaced Palette PNG', 50, 30);
doc.image('tests/images/issue-414-interlaced.png', 50, 50, {
width: 300,
});
});
});
});