batik: svg to pdf on linux (no X server)

心已入冬 提交于 2019-12-04 16:05:29

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

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
    
Rok Kralj

install imagemagick. Then call convert:

convert doc.svg doc.pdf

which will convert into a PDF.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!