Forum Bugs

Command line usage with raster output

ontic
Looking through your documentation it states:

Prince also accepts `-' meaning the standard output stream.


When I test producing a raster image using PHP and piping the input and output, the $stdout is always empty.

	function convertHtmlToPng($html)
	{
		$command = 'prince --raster-dpi=300 --raster-pages=first --raster-output=-';
		
		$descriptors = array(
			array('pipe', 'r'),
			array('pipe', 'w'),
			array('pipe', 'w'),
		);
		
		$process = proc_open($command, $descriptors, $pipes, null, null);
		
		if (!is_resource($process))
		{
			throw new Exception('Failed to execute command and open file pointers.');
		}
		
		fwrite($pipes[0], $html);
		fclose($pipes[0]);
		$stdout = stream_get_contents($pipes[1]);
		fclose($pipes[1]);
		$stderr = stream_get_contents($pipes[2]);
		fclose($pipes[2]);
		$result = proc_close($process);
		
		return $stdout;
	}


However when I define the output path the image is saved to the file system as expected.

$command = 'prince --raster-dpi=300 --raster-pages=first --raster-output=/home/user/test.png';


I've also tried the following command combinations which did not work either.

$command = 'prince --raster-dpi=300 --raster-pages=first --raster-output -';
$command = 'prince --raster-dpi=300 --raster-pages=first --raster-output=test.png --raster-output -';


Any help in being able to pipe the raster result would be much appreciated.
I'm using Prince Version 11-1 on Ubuntu 16.04
mikeday
You need to specify --raster-format=png (or jpeg) since it cannot be inferred from the output path.
mikeday
You need to specify --raster-format=png (or jpeg) since it cannot be inferred from the output path.
ontic
I tried as you suggested, however the returned output is a PDF file.

$command = 'prince --raster-dpi=300 --structured-log=buffered --raster-pages=first --raster-format=png -';
mikeday
You still need to specify --raster-output. How about this:
$command = 'prince --raster-dpi=300 --structured-log=buffered --raster-pages=first --raster-format=png --raster-output=-';
mikeday
Actually you will also need to add the input document URL to the command-line or another "-" if you're reading the input document from stdin:
$command = 'prince --raster-dpi=300 --structured-log=buffered --raster-pages=first --raster-format=png --raster-output=- -';
ontic
I tried your second command not long after I posted, you third command works like a charm.

Thanks for your guidance!