Setting density while converted a read stream doesn't affect the quality of pdf

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Setting density while converted a read stream doesn't affect the quality of pdf

Post by suman114 »

Hi,
I am converting a read stream data of pdf to another pdf with watermark. But adding density during this doesn't affect output.
How do I fix it?
I am using nodejs.
my try:

readStream.pipe(conversion code).pipe(writeStream);

Code: Select all

	var args = [ // using imagemagick convert command to add watermark
		'-density', '150',
		'-',
		'null:',
		'(',
			 path.join(root, 'public/assets/images/text_background.png'),
			 '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', '0.6', '+channel',
		')',
		'-gravity', 'southwest',
		'-quality', 100,
		'-fill', 'rgba(0,0,0,0.80)',
		'-pointsize', '10',
		'-weight', 'bold',
		'-annotate',
		'+0+2',
		text,
		'-layers', 'composite',
		'-'
	];
	
		var proc = spawn(command, args);

	var stream = new Stream();

	proc.stderr.on('data', stream.emit.bind(stream, 'error'));
	proc.stdout.on('data', stream.emit.bind(stream, 'data'));
	proc.stdout.on('end', stream.emit.bind(stream, 'end'));
	proc.on('error', stream.emit.bind(stream, 'error'));

	streamIn.pipe(proc.stdin);
	
	stream.pipe(writeStream);
	
	
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Setting density while converted a read stream doesn't affect the quality of pdf

Post by snibgo »

Showing sample inputs and output might help us to help you.

Please also say what version of IM and Ghostscript you use.
snibgo's IM pages: im.snibgo.com
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: Setting density while converted a read stream doesn't affect the quality of pdf

Post by suman114 »

snibgo wrote:Showing sample inputs and output might help us to help you.

Please also say what version of IM and Ghostscript you use.
IM 6.9.3-8
Ghostscript 9.20

Input: http://docdro.id/QSBrgbq

OutPut: https://www.docdroid.net/HiOZk4f/sumans ... 8.pdf.html

Notice the output is really poor.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Setting density while converted a read stream doesn't affect the quality of pdf

Post by snibgo »

Every page of that input PDF document contains one raster image that occupies the entire page. There is nothing else, except for the "PageMaster Demo" blurb on the front page.

If you want to add a watermark to each page, I suggest you extract the images with pdfimages (a tool available on Unix and Windows). Then use ImageMagick to modify each image, adding the watermark, and writing all the images to a single PDF file.
snibgo's IM pages: im.snibgo.com
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: Setting density while converted a read stream doesn't affect the quality of pdf

Post by suman114 »

snibgo wrote:Every page of that input PDF document contains one raster image that occupies the entire page. There is nothing else, except for the "PageMaster Demo" blurb on the front page.

If you want to add a watermark to each page, I suggest you extract the images with pdfimages (a tool available on Unix and Windows). Then use ImageMagick to modify each image, adding the watermark, and writing all the images to a single PDF file.

But the same pdf comes with fine quality when input as a file rather than a read stream
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Setting density while converted a read stream doesn't affect the quality of pdf

Post by snibgo »

Sorry, I know nothing about streams.
snibgo's IM pages: im.snibgo.com
Post Reply