-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmerge.go
41 lines (33 loc) · 1.01 KB
/
merge.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
package main
import (
"os"
"image"
"github.com/jung-kurt/gofpdf"
)
func merge (files []string, outputPath string) {
pdf := gofpdf.New("P", "mm", "A4", "")
for _, file := range files {
width, height := getImageDimension(file)
size := gofpdf.SizeType{ Wd: width, Ht: height }
pdf.AddPageFormat("P", size)
pdf.ImageOptions(
file, 0, 0, width, height, false,
gofpdf.ImageOptions{ ReadDpi: true },
0, "")
}
err := pdf.OutputFileAndClose(outputPath)
if err != nil {
logAndExit(err)
}
}
func getImageDimension(imagePath string) (float64, float64) {
file, err := os.Open(imagePath)
if err != nil {
logAndExit(err)
}
image, _, err := image.DecodeConfig(file)
if err != nil {
logAndExit(err)
}
return float64(image.Width), float64(image.Height)
}