Page 1 of 1

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

Posted: 2016-05-07T09:07:54-07:00
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);
	
	

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

Posted: 2016-05-07T09:18:40-07:00
by snibgo
Showing sample inputs and output might help us to help you.

Please also say what version of IM and Ghostscript you use.

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

Posted: 2016-05-07T09:47:32-07:00
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.

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

Posted: 2016-05-07T10:01:50-07:00
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.

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

Posted: 2016-05-07T20:09:35-07:00
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

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

Posted: 2016-05-08T02:31:53-07:00
by snibgo
Sorry, I know nothing about streams.