Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ type GoPdf struct {
fpdi *gofpdi.Importer
}

func NewFromBytes(pdfBytes []byte, config Config) (gp *GoPdf) {
gp = new(GoPdf)
gp.Start(config)

rs := io.ReadSeeker(bytes.NewReader(pdfBytes))

gp.fpdi.SetSourceStream(&rs)

templateID := gp.fpdi.ImportPage(1, "/MediaBox")
pageSizes := gp.fpdi.GetPageSizes()

for i := 1; i < len(pageSizes); i++ {
gp.AddPage()

if i > 1 {
Copy link
Copy Markdown
Contributor

@akhll akhll Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that i can be less than zero ?

templateID = gp.fpdi.ImportPage(i, "/MediaBox")
}

gp.fpdi.UseTemplate(
templateID,
0,
0,
pageSizes[i]["/MediaBox"]["w"],
pageSizes[i]["/MediaBox"]["h"])
}

return gp
}

//SetLineWidth : set line width
func (gp *GoPdf) SetLineWidth(width float64) {
gp.curr.lineWidth = gp.UnitsToPoints(width)
Expand Down