forked from signintech/pdft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_image_data.go
106 lines (90 loc) · 1.88 KB
/
pdf_image_data.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package pdft
import (
"bytes"
"encoding/base64"
gopdf "github.com/juaismar/pdft/minigopdf"
)
//PDFImageData pdf img
type PDFImageData struct {
objID int
imgObj gopdf.ImageObj
xObjChar string
xObjIndex int
}
/*
func (p *PDFImageData) setImgBase64(base64str string) error {
r := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer([]byte(base64str)))
err := p.imgObj.SetImage(r)
if err != nil {
return err
}
err = p.imgObj.Parse()
if err != nil {
return err
}
err = p.imgObj.Build(p.objID)
if err != nil {
return err
}
return nil
}*/
func createImgObjFromImgBase64(base64str string) (gopdf.ImageObj, *gopdf.SMask, error) {
r := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer([]byte(base64str)))
var imgObj gopdf.ImageObj
err := imgObj.SetImage(r)
if err != nil {
return gopdf.ImageObj{}, nil, err
}
err = imgObj.Parse()
if err != nil {
return gopdf.ImageObj{}, nil, err
}
smask, err := imgObj.CreateSMask()
if err != nil {
return gopdf.ImageObj{}, nil, err
}
return imgObj, smask, nil
}
func createImgObjFromBytes(img []byte) (gopdf.ImageObj, *gopdf.SMask, error) {
buff := bytes.NewBuffer(img)
var imgObj gopdf.ImageObj
err := imgObj.SetImage(buff)
if err != nil {
return gopdf.ImageObj{}, nil, err
}
err = imgObj.Parse()
if err != nil {
return gopdf.ImageObj{}, nil, err
}
smask, err := imgObj.CreateSMask()
if err != nil {
return gopdf.ImageObj{}, nil, err
}
return imgObj, smask, nil
}
func (p *PDFImageData) setImgObj(imgObj gopdf.ImageObj) error {
p.imgObj = imgObj
err := p.imgObj.Build(p.objID)
if err != nil {
return err
}
return nil
}
/*
func (p *PDFImageData) setImg(img []byte) error {
buff := bytes.NewBuffer(img)
err := p.imgObj.SetImage(buff)
if err != nil {
return err
}
err = p.imgObj.Parse()
if err != nil {
return err
}
err = p.imgObj.Build(p.objID)
if err != nil {
return err
}
return nil
}
*/