Page 1 of 1

convert from svg to pdf size incorrect

Posted: 2020-05-01T00:37:25-07:00
by hairykid
Hi all,

Having some issues with converting to PDF from SVG.

I'm using - Version: ImageMagick 7.0.9-14 Q16 x86_64 2020-01-08

This was working before but has since stopped working corectly. The only thing I believe that has changed is we now use InkScape, although I could be wrong, I'm not 100% inscape is being used with our command.

I've checked the calculation for the density vs size and it seems to be correct. Our output size needs to be 220x210mm, which at 300ppi is around 2598x2480px.

However the size we are now getting is around 80mm.

The command we are using is -

convert preview-69274097-LZV5Z7 -density 300 -size 2598x2480 pdf:/preview-35513468-dEbOXv

Please excuse the lack of file extensions, this is just how our inherited application works. So just to reiterate this is a conversion from SVG to PDF

Any help figuring this out woukld be appreciated.

Thanks

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T03:50:09-07:00
by snibgo
You might want a "-density" before reading the SVG.

Your "-size 2598x2480" does nothing. It has no effect. Is that a typo for "-resize 2598x2480"?

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T04:19:39-07:00
by hairykid
Hi, thanks for the reply.

I tried resize rather than size but no change to the size being outputted. It wasn't a typo but this was working previously so it must have worked at some point?

I tried adding '-density 300' before the svg filename but this just timed out when I tried to run it.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T04:40:21-07:00
by hairykid
Ok so upon playing around I can now get the desired size I need but it doesn't seem to match up with the dpi being used.

Let me just make sure this is correct, i.e my calculations.

For 220mm x 210mm

first convert to inches

8.66 x 8.26

Then multiple by 300 which equals

2598 x 2178

When running the following command

convert thesvg -density 300 -resize 2598x2178 pdf:./converted

This equals = 76x72mm

Then just to check the resize is working I ran

convert thesvg -density 300 -resize 9664x9224 pdf:./converted

This equals = 322x307mm

So it is resizing but just not how I would have expected. (From my limited perspective)

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T05:17:42-07:00
by snibgo
Your arithmetic is incorrect. 8.26 inches multiplied by 300 pixels per inch is 2478 pixels, not 2178.

"-resize 2598x2478" will resize the image to fit inside that box. If you want to ensure the result is exactly that size, either use "!" or "-extent" after the "-resize".

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T05:30:10-07:00
by hairykid
Thanks, however the outcome is the same when using 2478 for the height.

I have tried adding -extent but the error states

convert: invalid argument for option '-resize': -extent @ error/convert.c/ConvertImageCommand/2607.

I tried adding it directly after the -resize flag and also after the dimensions.

I have also tried

convert thesvg -density 300 -resize 2598x2478! pdf:./converted

and

convert thesvg -density 300 -resize 2598x2478\! pdf:./converted

With very similar results in size.

Not sure what is going on.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-01T06:10:54-07:00
by snibgo
hairykid wrote:invalid argument for option '-resize': -extent
Your command is bad. "-resize" needs size arguments. So does "-extent".

As you are using IM v7, I suggest you use "magick", not "convert". Windows BAT syntax:

Code: Select all

magick rose: -density 300 -resize "2598x2478^!" x.pdf
According to Adobe Acrobat Reader, x.pdf is the required 8.66 x 8.26 inches.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-11T05:00:32-07:00
by hairykid
Can't get this working at all, it is printing at the correct size with this command -

Code: Select all

convert msvg:preview-1040876306-v872ZX -compress jpeg -density 300 -resize 2598x2480 pdf:preview-146307873-oLnPNf
However we had to stop using this and use inkscape instead because some linked CYMK images in the svg were coming out inverted, so now we are using.

Code: Select all

convert preview-770412126-L7njCy -compress jpeg -density 300 -resize 2598x2480 pdf:preview-1976866613-h1apUr
And the size just will not come out correct.

Will look into the magick command, I'm using Ubuntu however.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-11T05:11:55-07:00
by hairykid
When I double the size something strange happens, it takes around 40 seconds to convert, and the command (which has doubled the original size I was using)

Code: Select all

convert preview-514774901-d4GCeK -compress jpeg -density 300 -resize 5196x4960 pdf:preview-841203687-s64sFe
Prints out at 6.81 x 6.5 inches

Re: convert from svg to pdf size incorrect

Posted: 2020-05-11T10:11:02-07:00
by snibgo
hairykid wrote:And the size just will not come out correct.
Your statement is too vague for us to offer advice.

If you have a specific problem, please include enough for us to reproduce the problem. This must include the input file(s), the command, and what happens that you don't like.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-12T23:27:16-07:00
by hairykid
Sure, thanks.

So my spec

Version: ImageMagick 7.0.9-14 Q16 x86_64 2020-01-08 Ubuntu 18.04

Then the command being used is -

convert preview-640617540-fLJb3I -density 300 -resize 2598x2480 pdf:preview-1640217103-PtgKIh

Both files are here - https://gofile.io/d/wYivCg

I have added the file extension onto both but this command runs without extensions.

The aim with this command is to get a PDF which is 8.6 inches x 8.26 inches, however the output is 3.4 inches x 3.2 inches.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-13T16:37:26-07:00
by snibgo
For v7, I suggest you use "magick", not "convert".

With IM v7.0.8-64:

Code: Select all

magick preview-640617540-fLJb3I.svg -density 300 -resize 2598x2480 pdf:p.pdf
Adobe Acrobat Reader v2020.006.20042 says p.pdf is 8.66 x 8.27 inches.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-14T00:10:16-07:00
by hairykid
Still prints as 3.4 x 3.25

I give up.

Thanks for your help but I need to find another solution, this project is driving me up the wall.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-14T09:44:36-07:00
by fmw42
Perhaps your printer has some scaling options that you need to reset.

Re: convert from svg to pdf size incorrect

Posted: 2020-05-14T10:40:56-07:00
by snibgo
@hairykid: Are you measuring the size made by a printer? If so, I suggest you use Adobe Acrobat Reader, menu File, Properties. What does it say the "Page Size" is? If that is what you want, the problem is downstream, eg in printer settings.