Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid ColorSpace error in PDF files in Acrobat or Reader #1601

Open
ggvattenfall opened this issue Mar 3, 2025 · 0 comments
Open

Invalid ColorSpace error in PDF files in Acrobat or Reader #1601

ggvattenfall opened this issue Mar 3, 2025 · 0 comments

Comments

@ggvattenfall
Copy link

ggvattenfall commented Mar 3, 2025

Bug Report

Invalid ColorSpace error in PDF files in Acrobat or Reader

Description of the problem

There is an error displayed in Adobe Reader 'Invalid ColorSpace error in PDF files in Acrobat or Reader' while opening the PDF/A-3a file generated in PDFKit. When I remove the subset of PDF/A-3a Adobe doesn't throw any errors and opens the file correctly.

I'm working in latest angular version and latest pdfkit.

Code sample

`

import blobStream from 'blob-stream';
import pdfkit from 'pdfkit';

async createPdf(htmlDoct: string) {
const doc = new pdfkit({
pdfVersion: '1.7',
subset: 'PDF/A-3a',
tagged: true,
displayTitle: true,
size: 'A4',
bufferPages: true,
margin: 30,
});
// draw some text
doc.fontSize(25).text('Here is some vector graphics...', 100, 80);

// some vector graphics
doc
.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill('#FF3300');

doc.circle(280, 200, 50).fill('#6600FF');

// an SVG path
doc
.scale(0.6)
.translate(470, 130)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore();

doc.save();
// a gradient fill
var gradient = doc
.linearGradient(100, 300, 200, 300)
.stop(0, 'green')
.stop(0.5, 'red')
.stop(1, 'green');
doc.rect(100, 300, 100, 100).fill(gradient);
let stream = doc.pipe(blobStream());

// stroke & fill uncolored tiling pattern

var stripe45d = doc.pattern(
[1, 1, 4, 4],
3,
3,
'1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
);
doc.circle(280, 350, 50).fill([stripe45d, 'blue']);

doc
.rect(380, 300, 100, 100)
.fillColor('lime')
.strokeColor([stripe45d, 'orange'])
.lineWidth(5)
.fillAndStroke();
doc.restore();

// and some justified text wrapped into columns
doc
.text('And here is some wrapped text...', 100, 450)
.font('Times-Roman', 13)
.moveDown()
.text('lorem', {
width: 412,
align: 'justify',
indent: 30,
columns: 2,
height: 300,
ellipsis: true
});

doc.end();
stream.on('finish', () => {
  window.open(stream.toBlobURL('application/pdf'));
});

}
`

my webpack config export file :

`

 module.exports = {

plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
}),
new webpack.DefinePlugin({
output: {
path: path.resolve(__dirname, '/dist/apps/' + project),
},
}),
],
resolve: {
symlinks: false,
alias: {
// maps fs to a virtual one allowing to register file content dynamically
fs: __dirname + '/virtual-fs.js'
},
fallback: {
// crypto module is not necessary at browser
crypto: false,
// fallbacks for native node libraries
buffer: require.resolve('buffer/'),
stream: require.resolve('readable-stream'),
zlib: require.resolve('browserify-zlib'),
util: require.resolve('util/'),
assert: require.resolve('assert/'),
fs: require.resolve('fs'),
},
},

module: {
rules: [
{ test: /.afm$/, type: 'asset/source' },
{ test: /.icc$/, type: 'asset/source' },
{ test: /.png$/, type: 'asset/source' },
{
test: /src[/\]static-assets/,
type: 'asset/inline',
generator: {
dataUrl: (content) => {
return content.toString('base64');
},
},
},
// load binary files inside lazy-assets folder as an URL
{
test: /src[/\]lazy-assets/,
type: 'asset/resource',
},
],
},
};

`

Your environment

  • pdfkit version: 0.16.0
  • Node version:
  • Browser version (if applicable):
  • Operating System:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant