Page 1 of 1
-page and -density not compatible?
Posted: 2014-03-24T06:36:08-07:00
by areslagae
Hi all,
I want to center a raster image (PNG) in an A4-sized PDF with a given DPI. However, it seems that the -page and -density options for convert are not compatible.
- This command line works using (apparently) 72 DPI:
convert rose: -page a4 -gravity center rose.pdf
- However, I have a 300 DPI image. I tried this command line but it does not work as expected (I get a blank PDF):
convert rose: -density 300 -page a4 -gravity center rose.pdf
- The density option withouth the page argument does seem to work however:
convert rose: -density 300 rose.pdf
Does anyone know what is going on here?
Thanks,
Re: -page and -density not compatible?
Posted: 2014-03-24T09:54:02-07:00
by fmw42
pdf files are vector files (or vector files containing raster data). A vector file has no resolution or density until you assign it a density when reading it it (for conversion or printing).
Re: -page and -density not compatible?
Posted: 2014-03-25T01:50:46-07:00
by areslagae
OK, in that case let me reformulate my question: How do I control the size of the raster image in the PDF file? I use DPI for that, but I could also specify the desired size (which basically boils down to the same thing ...).
Re: -page and -density not compatible?
Posted: 2014-03-25T10:35:19-07:00
by fmw42
resize the raster image using -resize before writing to vector output format
but I do not know if that really helps, because once you have a vector format, you need to specify the density when reading it so that it can be printed accordingly.
Re: -page and -density not compatible?
Posted: 2014-03-25T11:14:37-07:00
by snibgo
I know almost nothing about PDF, but "-page A4" seems (
http://www.imagemagick.org/script/comma ... s.php#page) to be a shortcut for "-page 595x842", which is fine for 72 DPI but not other densities.
Try this:
Code: Select all
convert -size 1200x1200 gradient: -density 300 g.png
convert g.png -page 2480x3508+200+300 g.pdf
g.png is just a sample image at 300 dpi. 2480x3508 is A4 at 300 dpi. Adjust the offsets to suit.
Re: -page and -density not compatible?
Posted: 2014-03-26T01:58:32-07:00
by areslagae
snibgo's snippet seems to work. Many thanks!
I am just wondering about the following: The generated PDF has a size (according to acroread) of 8.27 x 11.69 inch, which is A4. How does imagemagick infer the size in inches from the pixel resolution? Or is the density setting actuallty stored in the PNG file and used when converting to PDF?
Re: -page and -density not compatible?
Posted: 2014-03-26T07:59:13-07:00
by snibgo
Yes, g.png contains metadata 300 dpi. "-page" sets the overall width to 2480 pixels, which is 2480/300 = 8.2666 inches. Likewise for height.