galihrivanto / go-inkscape

a proxy for inkscape --shell mode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-inkscape

go.dev reference

a proxy to interfacing with inkscape --shell mode

motivation

while golang have some great pdf libraries but currently there's no one support complete svg conversion to pdf. this library attempt to provide interfacing with wellknown inkscape to manipulate svg, pdf and other supported formats using --shell mode and action-command

install

go get github.com/galihrivanto/go-inkscape

simple usage

package main

import (
	"flag"
	"fmt"
	"github.com/galihrivanto/go-inkscape"
	"os"
)

var (
	svgInput  string
	pdfOutput string
)

func handleErr(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func main() {
	flag.StringVar(&svgInput, "input", "", "svg input")
	flag.StringVar(&pdfOutput, "output", "result.pdf", "pdf output")
	flag.Parse()

	if svgInput == "" {
		fmt.Println("svg input is missing")
		os.Exit(1)
	}

	proxy := inkscape.NewProxy(inkscape.Verbose(true))
	err := proxy.Run()
	handleErr(err)
	defer proxy.Close()

	err = proxy.Svg2Pdf(svgInput, pdfOutput)
	handleErr(err)

	fmt.Println("done!!")
}

advanced usage

...
proxy.RawCommands(
    "file-open:test.svg",
    "export-filename:out.pdf",
    "export-do",
)
...

license

MIT

About

a proxy for inkscape --shell mode

License:MIT License


Languages

Language:Go 100.0%