-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdtosvg.go
42 lines (37 loc) · 911 Bytes
/
pdtosvg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2009 Helmar Wodtke. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// The MIT License is an OSI approved license and can
// be found at
// http://www.opensource.org/licenses/mit-license.php
// Convert PDF-pages to SVG.
package main
import (
"fmt"
"os"
"pdfread"
"strm"
"svg"
)
// The program takes a PDF file and converts a page to SVG.
func complain(err string) {
fmt.Printf("%susage: pdtosvg foo.pdf [page] >foo.svg\n", err)
os.Exit(1)
}
func main() {
if len(os.Args) == 1 || len(os.Args) > 3 {
complain("")
}
page := 0
if len(os.Args) > 2 {
page = strm.Int(os.Args[2], 1) - 1
if page < 0 {
complain("Bad page!\n\n")
}
}
pd := pdfread.Load(os.Args[1])
if pd == nil {
complain("Could not load pdf file!\n\n")
}
fmt.Printf("%s", svg.Page(pd, page))
}