2

Similar to approach in Convert SVG to PDF the svg2pdf conversion runs successfully under windows and text items are searchable in the resulting pdf. It produces pdfs (with -Djava.awt.headless=true to avoid exceptions due missing X11 window server) under linux (Ubuntu) as well, but the text items are not searchable and sometimes are even coded as images.

Is it possible to preserve text in pdf under linux as well, am I missing some runtime options?

UPD: Can I somehow force batik (SVGGraphics2D or SVGConverter) to fall back to a default font, if certain font wasn't found?

Community
  • 1
  • 1
D_K
  • 1,410
  • 12
  • 35
  • Odd. Are all the fonts available on both machines? Did you try with the standard PDF fonts (Times New Roman, ...) or are you using custom TrueType fonts? – Aaron Digulla Feb 16 '12 at 14:21
  • @AaronDigulla I don't control the fonts, because they come from pptx files of random sort. The cycle is: pptx->svg_files->pdf_files->one_pdf_file. But fonts availability was my first concern. Could I somehow copy the fonts from win->linux box? – D_K Feb 16 '12 at 15:10
  • from the (suggested by @Rok Kralj) imagemagick's 'identify -list format' cmd I can see that TrueType font collection is missing completely from my linux box. That seems to be the issue with batik – D_K Feb 16 '12 at 15:48
  • I think that AWT does not send text primitives to Batik but paths, that's why you can't find the text. One reason for this could be to ensure identical look on all systems, which is not guaranteed with font (commercialization). Maybe there's an AWT switch for this behaviour. – rwst Aug 01 '12 at 08:09
  • 1
    This would help to make available missing TTF fonts in Linux servers and to java applications : http://stackoverflow.com/questions/17993130/svg-to-png-text-not-showing-properly-arial-font/17993932?noredirect=1#17993932. – Shantha Kumara Aug 02 '13 at 04:59

4 Answers4

2

Solved by following the recipe here:

http://batik.2283329.n4.nabble.com/Placing-SVG-Text-into-PDF-td3778127.html

major steps:

  1. compile fop with ant all
  2. copy fop-transcoder-allinone.jar under name pdf-transcoder.jar into the classpath
  3. copy xmlgraphics-commons-1.4.jar from fop's lib directory into the classpath
D_K
  • 1,410
  • 12
  • 35
1

If you want to copy a font from Windows to Linux, you only need to copy the .ttf file to the right place (note: Some fonts are copyrighted and you need permission to install them). There is no need to put them into some kind of registry.

To make them available in Java, you have two options:

  1. You can set the environment variable JAVA_FONTS before running batik

  2. Open font.properties file in the jre/lib directory, uncommnent and set to the appropriate font directory:

    appendedfontpath=/usr/share/fonts/truetype
    
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • this is really helpful, thanks a lot. I'm copying the fonts at the moment and will include them as well, as some conversions under linux had extra spaces between the letters – D_K Feb 21 '12 at 08:52
0

Try to add definitions (with url) for those fonts you want to use:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="745" height="300" xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace">
    <desc>TEST</desc>
    <defs>
        <style type="text/css">
            @font-face {
                font-family: "font";
                src: url('COMPLETE URL TO TTF FILE eg. http://example.com/font.ttf') format('truetype');
            }
        </style>
    </defs>
    <g transform="translate(174.5 53)">
        <text font-family="font" font-size="40" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #333; opacity: 1;" transform="translate(-98.5 39)">
            <tspan x="0" y="-26" fill="#333">TEXT THAT YOU WANT TO DISPLAY</tspan>
        </text>
    </g>
</svg>

I had the same problem. One thing that i forgot in svg was type="text/css".

ryszardPL
  • 41
  • 3
-1

install imagemagick. Then call convert:

convert doc.svg doc.pdf

which will convert into a PDF.

glglgl
  • 89,107
  • 13
  • 149
  • 217
Rok Kralj
  • 46,826
  • 10
  • 71
  • 80
  • hm, the convert produces Non-conforming drawing primitive definition `Dialog''' @ draw.c/DrawImage/3140. – D_K Feb 17 '12 at 08:55