svg to pdf

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
GLorenz
Posts: 4
Joined: 2014-03-27T07:06:53-07:00
Authentication code: 6789

svg to pdf

Post by GLorenz »

Hello,

I am new to ImageMagick, but since I've looked for the answer to this almost a whole day, I need to open a new question.

My problem is, that I am trying to convert an svg to pdf. So far the convert command works fine, aside of the fact that in the conversion the text elements of the svg lose any font type or family.
I tried to create an type.xml file in various directories, since the imageMagick installation is beyond the scope of my user rights on the server I got no luck with that.

However, it would actually make more sense for me to put the pathes of my fonts directly into the command line anyways.
Ensuing, actual problem: How exactly does the command line syntax of an SVG to PDF conversion look, where several external fonts need to be included?

I am not having any luck with my attempts so far.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: svg to pdf

Post by snibgo »

As you probably know, SVG and PDF are both vector formats. So text is stored as "abc" or whatever. But ImageMagick will rasterise this -- convert this to dots, at a given resolution -- and embed this raster image with the PDF.

To keep the data in vector format, a different tool should be used.

On fonts: there seems to be a difficulty using IM (or Inkscape as a delegate) to convert SVG files that use fonts that are not installed on the system. The delegate that processes the SVG doesn't use IM mechanisms to find the font. Instead, it uses the operating system to find the font.

I don't think there is much the IM people can do to fix this difficulty. Perhaps the Inkscape people could do something.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: svg to pdf

Post by fmw42 »

It should work if you are calling fonts that you have installed and IM knows about them. You can alway use known fonts in your svg file. I think there was a recent post about that. If you need to modify your list of fonts on unix. See the script, imagick_type_gen, at http://www.imagemagick.org/Usage/scripts/

Nevertheless, IM is not the best tool for vector to vector conversion. See http://www.imagemagick.org/Usage/formats/#vector
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: svg to pdf

Post by snibgo »

Another note: when used interactively, Inkscape can save an SVG file as PDF, keeping the vector nature. Text can be copied from the resulting PDF, as text. Perhaps a suitable entry could be made in delegates.xml to do this vector->vector via ImageMagick, though I can't see any point.

However, if the SVG file specifies a font that isn't installed, Inkscape substitutes one that is installed, and the PDF file uses this installed font.
snibgo's IM pages: im.snibgo.com
GLorenz
Posts: 4
Joined: 2014-03-27T07:06:53-07:00
Authentication code: 6789

Re: svg to pdf

Post by GLorenz »

Thanks for the replies and sorry for the late response.

Yes, I am aware that the resulting pdf will be no longer a vector graphic, it doesn't need to be. Imagick was already installed on this server when the project started, so it was used for convenience.

I generated a type.xml file with the imagick_type_gen, my problem seems merely to be that ImageMagick does not find or use this file, the -list font command only returns system fonts and some fonts in the imagick directory.

So what I need is some advice on what I need to do to make Imagick recognize my type.xml file.


OR, and that would actually be more convenient, how the exact syntax needs to be to hand Imagick a font file path in the convert command line itself.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: svg to pdf

Post by snibgo »

What is your platform, and where did you put your new type.xml?

On Windows 8.1, my personal type.xml goes in ~\.magick\, where ~ is my home directory. "convert -list font" shows entries in that type.xml, and "convert -font AnniSnib label:"Hello world" x.png" works fine, where AnniSnib is an entry in type.xml, pointing to a ttf file that isn't installed in Windows.

Another command that works: convert -font f:\web\im\annifont.ttf label:"Hello world" x.png

However, as I mentioned above, an SVG can't successfully refer to AnniSnib. I would have to install the font, through Windows, for that.
snibgo's IM pages: im.snibgo.com
GLorenz
Posts: 4
Joined: 2014-03-27T07:06:53-07:00
Authentication code: 6789

Re: svg to pdf

Post by GLorenz »

It's some unix server. Imagick is preinstalled and following the configuration path orders I tried put the type xml in the current directory (where the php file lies calling the command) and also tried to set the $MAGICK_FONT_PATH to where my type.xml files is.

I unfortunately have no direct access to the Imagick directory itself.


If I let my svg refer to the font with the font file path instead of any alias, it should work, shouldn't it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: svg to pdf

Post by snibgo »

I don't know PHP, but obviously it needs to know the value of $MAGICK_FONT_PATH. Echoing the value or directory listing to the web page might provide a clue. As might "-debug all".

Give the font filename in the SVG? Well, you can try it, but the SVG spec doesn't give that as an option. See http://www.w3.org/TR/SVG/text.html#Font ... sUsedBySVG
snibgo's IM pages: im.snibgo.com
GLorenz
Posts: 4
Joined: 2014-03-27T07:06:53-07:00
Authentication code: 6789

Re: svg to pdf

Post by GLorenz »

I'll try a debug -all once my server is done with updating tasks.

I guess whether or not the font file name in the svg works depends on how the Imagick converter engine interpretes the font-tag of the svg. Using @font-face we've had no problem rendering the svg at least.

Even though I am currently trying to get tcpdf to work as an alternative, it'd still be nice to figure this one here out just in case.

Thanks a lot so far.
Post Reply