I'm trying to use pdftoppm to scale my pdfs to width 800 with correct aspect ratio but I noticed that pdftoppm -scale-to-x doesn't handle aspect ratio at all and stretches the image. My solution was to use pdfinfo to get the size and calculate correct scale-to box which worked well until I needed to deal with pdfs with wrong meta data, for example mediabox and pagesize swapped, width is actually height and vice versa. If I don't specify any parameters or use -scale-to parameter the output is correct. If -scale-to parameter would accept two sizes -scale-to=x,y then I could use 800,100000 or something similar, it would be very handy to be able to scale to fixed with and maintain aspect ratio whether it would be done with -scale-to-x parameter alone or with extended version of -scale-to parameter or event introduce new parameter.
Created attachment 57626 [details] [review] fix aspect ratio When only one of -scale-to-x or -scale-to-y is used the other should be set based on the aspect ratio. The attached patch fixes this.
To be honest i'm not convinced by that patch. The manual option clearly says -scale-to-x number Scales each page horizontally to fit in scale-to-x pixels. Does not mention it will change the y pixels when i did not ask for it.
The -scale-to option also does not do what the man page says. -scale-to number Scales each page to fit in scale-to*scale-to pixel box. It says it will scale to the same number of pixel in each direction. What the code does is use the scale-to size for the longest side and sets the other side based on the aspect ratio.
Albert: this option is really useless in most cases as it will stretch or narrow the image and destroy it's aspect ratio. In my opinion it will fit more use cases following aspect ratio. I think that we could also change the parameter description in man page to state that it will follow aspect ratio. Also new option could be introduced, for example --keep-aspect-ratio that when used would have the effect of Adrian's patch.
Note: The fact that in your opinion an option is useless means nothing, you are not the only one using pdftoppm. I'm sure that thre is someone using it somewhere and when you change the behaviour it's me as the maintainer that is going to be blamed, not you ;-) @Adrian : Let's fix it then ;-) My suggestion: * Update pdftoppm manage to mention that scale-to-x keeps aspect ratio by default * Make it so that if you pass -1 as one of the scaleXorScaleY parameters means it will maintain the aspect ratio if the other one is specified and put it on the manpage. What you guys think?
I like your suggestion as it adds required functionality without breaking backwards compatibility.
Created attachment 57706 [details] [review] allow -1 to mean aspect ratio is preserved
Created attachment 57707 [details] [review] document that -scale-to preserves aspect ratio If these two patches are accepted I will update pdftocairo to work the same way.
Looks good to me, please commit :-)
pushed
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.