forked from signintech/pdft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf_img_test.go
57 lines (47 loc) · 6.08 KB
/
pdf_img_test.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
package pdft
import (
"encoding/base64"
"io/ioutil"
"os"
"testing"
)
func TestInsertImage(t *testing.T) {
imgBase64 := "iVBORw0KGgoAAAANSUhEUgAAAYwAAAArCAYAAABrV7+oAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA5rSURBVHherY5Bii1JEMP6/pf+sxJ4RBkHvBR4EbKzqL9/j/n7+/tfwHej7fDXnhj7tXOgeVjeMa33DbnNQPOwvAPNw/KOaf3VE7O8e3tilndvT8zy156Ab8htBnxDbn/pTb7JQPPgnoBvWL710Pp8+9WDdwTabf+K519sP+y70Xb4a0+M/do50Dws75jW+4bcZqB5WN6B5mF5x7T+6olZ3r09Mcu7tydm+WtPwDfkNgO+Ibe/9CbfZKB5cE/ANyzfemh9vv3qwTsC7bZ/xfMvth/23Wg7/LUnxn7tHGgelndM631DbjPQPCzvQPOwvGNaf/XELO/enpjl3dsTs/y1J+AbcpsB35DbX3qTbzLQPLgn4BuWbz20Pt9+9eAdgXbbv+L5F9sP+260Hf7aE2O/dg40D8s7pvW+IbcZaB6Wd6B5WN4xrb96YpZ3b0/M8u7tiVn+2hPwDbnNgG/I7S+9yTcZaB7cE/ANy7ceWp9vv3rwjkC77V/x/Ivth3032g5/7YmxXzsHmoflHdN635DbDDQPyzvQPCzvmNZfPTHLu7cnZnn39sQsf+0J+IbcZsA35PaX3uSbDDQP7gn4huVbD63Pt189eEeg3faveP7F9sO+G22Hv/bE2K+dA83D8o5pvW/IbQaah+UdaB6Wd0zrr56Y5d3bE7O8e3tilr/2BHxDbjPgG3L7S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3r09MctfewK+IbcZ8A25/aU3+SYDzYN7Ar5h+dZD6/PtVw/eEWi3/Suef7H9sO9G2+GvPTH2a+dA87C8Y1rvG3KbgeZheQeah+Ud0/qrJ2Z59/bELO/enpjlrz0B35DbDPiG3P7Sm3yTgebBPQHfsHzrofX59qsH7wi02/4Vz7/Yfth3o+3w154Y+7VzoHlY3jGt9w25zUDzsLwDzcPyjmn91ROzvHt7YpZ3b0/M8teegG/IbQZ8Q25/6U2+yUDz4J6Ab1i+9dD6fPvVg3cE2m3/iudfbD/su9F2+GtPjP3aOdA8LO+Y1vuG3GageVjegeZhece0/uqJWd69PTHLu7cnZvlrT8A35DYDviG3v/Qm32SgeXBPwDcs33pofb796sE7Au22f8XzL7Yf9t1oO/y1J8Z+7RxoHpZ3TOt9Q24z0Dws70DzsLxjWn/1xCzv3p6Y5d3bE7P8tSfgG3KbAd+Q2196k28y0Dy4J+Ablm89tD7ffvXgHYF227/i+RfbD/tutB3+2hNjv3YONA/LO6b1viG3GWgelnegeVjeMa2/emKWd29PzPLu7YlZ/toT8A25zYBvyO0vvck3GWge3BPwDcu3Hlqfb7968I5Au+1f8fyL7Yd9N9oOf+2JsV87B5qH5R3Tet+Q2ww0D8s70Dws75jWXz0xy7u3J2Z59/bELH/tCfiG3GbAN+T2l97kmww0D+4J+IblWw+tz7dfPXhHoN32r3j+xfbDvhtth7/26zuwdg40D8s7pvW+IbcZaB6Wd6B5WN4xrb96YpZ3b0/M8u7tiVn+2hPwDbnNgG/I7S+9yTcZaB7cE/ANy7ceWp9vv3rwjkC77V/x/Ivth3032g5/7YmxXzsHmoflHdN635DbDDQPyzvQPCzvmNZfPTHLu7cnZnn39sQsf+0J+IbcZsA35PaX3uSbDDQP7gn4huVbD63Pt189eEeg3fZv+PfvP+0isqPiLi+lAAAAAElFTkSuQmCC"
//imgpath := "./test/img/gopher.png"
/*_, rawData, err := readImg(imgpath)
if err != nil {
t.Error("Couldn't read image")
return
}*/
//filename := "tmpl_empty.pdf"
//var ipdf PDFt
//err := ipdf.Open("test/pdf/pdf_from_docx_with_f.pdf")
filename := "pdf_from_docx_with_f.pdf"
var ipdf PDFt
//err := ipdf.Open("test/pdf/pdf_from_docx_with_f.pdf")
err := ipdf.Open("test/pdf/" + filename)
if err != nil {
t.Fatalf("%v", err)
return
}
//ipdf.InsertImg(rawData, 1, 100.0, 100.0, 100, 100)
ipdf.InsertImgBase64(imgBase64, 1, 100.0, 100.0, 100, 100)
err = ipdf.Save("/Users/oneplus/Desktop/pdf/out3_" + filename)
if err != nil {
t.Errorf("Couldn't save pdf. %+v", err)
return
}
}
func readImg(path string) (string, []byte, error) {
f, err := os.OpenFile(path, os.O_RDONLY, 0777)
if err != nil {
return "", nil, err
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
return "", nil, err
}
encoded64 := base64.StdEncoding.EncodeToString(data)
return encoded64, data, nil
}