convert from svg to pdf size incorrect

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

convert from svg to pdf size incorrect

Post 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

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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"?
snibgo's IM pages: im.snibgo.com

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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)

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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".
snibgo's IM pages: im.snibgo.com

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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.
snibgo's IM pages: im.snibgo.com

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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.

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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.
snibgo's IM pages: im.snibgo.com

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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.
snibgo's IM pages: im.snibgo.com

hairykid
Posts: 39
Joined: 2019-03-12T08:30:40-07:00
Authentication code: 1152

Re: convert from svg to pdf size incorrect

Post 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.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert from svg to pdf size incorrect

Post by fmw42 »

Perhaps your printer has some scaling options that you need to reset.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert from svg to pdf size incorrect

Post 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.
snibgo's IM pages: im.snibgo.com

Locked