-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
79 lines (64 loc) · 2.2 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"os"
flag "github.com/ogier/pflag"
unicommon "github.com/unidoc/unidoc/common"
"github.com/unidoc/unidoc/pdf/creator"
)
var size, margin string
var scaleH, scaleW, landscape, verbose, version bool
var JPEGQuality int
const (
DefaultSize = "IMG-SIZE"
DefaultMargin = "0,0,0,0"
VERSION = "1.2.0"
)
func init() {
flag.StringVarP(&size, "size", "s", DefaultSize, "Resize image pages to print size. One of A4, A3, Legal or Letter.")
flag.StringVarP(&margin, "margin", "m", DefaultMargin, "Comma separated numbers for left, right, top, bottm side margin in inch.")
flag.BoolVar(&scaleW, "scale-width", false, "Scale Image to page width. Only if --size specified.")
flag.BoolVar(&scaleH, "scale-height", false, "Scale Image to page height. Only if --size specified.")
flag.IntVar(&JPEGQuality, "jpeg-quality", 100, "Optimize JPEG Quality.")
flag.BoolVarP(&landscape, "landscape", "l", false, "Set image page size in Landscape mode.")
flag.BoolVarP(&verbose, "verbose", "v", false, "Display debug information.")
flag.BoolVarP(&version, "version", "V", false, "Display Version information.")
flag.Usage = func() {
fmt.Println("merge2pdf [options...] <output_file> <input_file> [<input_file>...]")
fmt.Println("<output_file> should be a PDF file and <input_file> can be PDF, image or directory. PDF files can have specific page numbers to merge.")
fmt.Println("Example: merge2pdf output.pdf input1.pdf input_pages.pdf~1,2,3 input3.jpg /path/to/dir ...")
fmt.Println("Available Options: ")
flag.PrintDefaults()
}
}
func main() {
flag.Parse()
if version {
fmt.Println("merge2pdf version ", VERSION)
os.Exit(0)
}
args := flag.Args()
if len(args) < 2 {
flag.Usage()
os.Exit(0)
}
if verbose {
unicommon.SetLogger(unicommon.NewConsoleLogger(unicommon.LogLevelDebug))
}
outputPath := args[0]
inputPaths := args[1:]
c := creator.New()
for _, arg := range inputPaths {
err := NewSource(arg).MergeTo(c)
if err != nil {
fmt.Printf("Error: %s (%s) \n", err.Error(), arg)
os.Exit(1)
}
}
err := c.WriteToFile(outputPath)
if err != nil {
fmt.Printf("Error: %s \n", err.Error())
}
debugInfo(fmt.Sprintf("Complete, see output file: %s", outputPath))
os.Exit(0)
}