Skip to content

Commit

Permalink
switched to modules, reduced deps
Browse files Browse the repository at this point in the history
  • Loading branch information
slinso committed Jan 11, 2021
1 parent c26f3a3 commit 51f55ea
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 71 deletions.
135 changes: 72 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,79 @@
# goreport

Golang Pdf Report Generator
[日本語の説明はこちら](https://github.com/mikeshimura/goreport/wiki/%E6%97%A5%E6%9C%AC%E8%AA%9E%E8%AA%AC%E6%98%8E)
[日本語の説明はこちら](https://github.com/SlinSo/goreport/wiki/%E6%97%A5%E6%9C%AC%E8%AA%9E%E8%AA%AC%E6%98%8E)

This program use github.com/signintech/gopdf for pdf generation.

Simple report sample
![Simple1](https://bytebucket.org/mikeshimura/goreport/wiki/image/simple1.jpg "Simple1")

[pdf](https://bytebucket.org/mikeshimura/goreport/wiki/pdf/simple1.pdf)
![Simple1](https://bytebucket.org/SlinSo/goreport/wiki/image/simple1.jpg 'Simple1')

[pdf](https://bytebucket.org/SlinSo/goreport/wiki/pdf/simple1.pdf)

Medium report sample
![Medium1](https://bytebucket.org/mikeshimura/goreport/wiki/image/medium1.jpg "Medium1")

[pdf](https://bytebucket.org/mikeshimura/goreport/wiki/pdf/medium1.pdf)

![Medium1](https://bytebucket.org/SlinSo/goreport/wiki/image/medium1.jpg 'Medium1')

[pdf](https://bytebucket.org/SlinSo/goreport/wiki/pdf/medium1.pdf)

Complex report sample
![Complex1](https://bytebucket.org/mikeshimura/goreport/wiki/image/complex1.jpg "Complex1")
![Complex1](https://bytebucket.org/SlinSo/goreport/wiki/image/complex1.jpg 'Complex1')

[pdf](https://bytebucket.org/mikeshimura/goreport/wiki/pdf/complex1.pdf)
[pdf](https://bytebucket.org/SlinSo/goreport/wiki/pdf/complex1.pdf)

![Complex2](https://bytebucket.org/SlinSo/goreport/wiki/image/complex2.jpg 'Complex2')

![Complex2](https://bytebucket.org/mikeshimura/goreport/wiki/image/complex2.jpg "Complex2")

[pdf](https://bytebucket.org/mikeshimura/goreport/wiki/pdf/complex2.pdf)
[pdf](https://bytebucket.org/SlinSo/goreport/wiki/pdf/complex2.pdf)

## Installation

```
go get -u github.com/mikeshimura/goreport
go get -u github.com/SlinSo/goreport
```

## concept

- Following Bands are available.
PageHeader
GroupHeader2
GroupHeader1
Detail
GroupSummary1
GroupSummry2
Summary
PageFooter
PageHeader
GroupHeader2
GroupHeader1
Detail
GroupSummary1
GroupSummry2
Summary
PageFooter

- Groups can be any number

- User defined Band structure required to implement Band interface.
Only two functions are required.

Only two functions are required.

```
GetHeight(report GoReport) float64
Execute(report GoReport)
```

- Two step executiion.
First step: Generate Text data.
Second step: Generate Pdf from Text data.
First step: Generate Text data.
Second step: Generate Pdf from Text data.

- Above two step execution enable very flexible usability.
You may generate Text data by program, then any kind of pdf can be generated.
You may generate Text data by program, then any kind of pdf can be generated.

- I use above flexibity to insert total pages data after generation automatically.
- I use above flexibity to insert total pages data after generation
automatically.

- Band height can be changed program, therefore conditional display can be achieved.
- Band height can be changed program, therefore conditional display can be
achieved.

- Data source is stored as []interface{}, then any kind of data type can be used. For example, string array, entity object, map etc.
- Data source is stored as []interface{}, then any kind of data type can be
used. For example, string array, entity object, map etc.

- Any Ttf Font can be used

## Setup Commands

- Font Setting Sample

```
font1 := gr.FontMap{
FontName: "IPAex",
Expand All @@ -78,74 +82,79 @@ font1 := gr.FontMap{
fonts := []*gr.FontMap{&font1}
r.SetFonts(fonts)
```

- Page Setting
SetPage(size string, unit string, orientation string)
//size A4 or LTR, unit mm, pt or in
SetPage(size string, unit string, orientation string)
//size A4 or LTR, unit mm, pt or in

SetPageByDimension(unit string, width float64, height float64)
- Normal Print limit setting. PageFooter(if defined) will be written after reach this limt.
SetFooterY(footerY float64)
SetPageByDimension(unit string, width float64, height float64)

SetFooterYbyFooterHeight(footerHeight float64)
//Sheet height - footerHeight will be set
- Normal Print limit setting. PageFooter(if defined) will be written after reach
this limt.
SetFooterY(footerY float64)

SetFooterYbyFooterHeight(footerHeight float64)
//Sheet height - footerHeight will be set

## Draw Commands

- New Page
NewPage(resetPageNo bool)

NewPage(resetPageNo bool)

- Font setting
Font(fontName string, size int, style string)
//style "" or "U" (underline)
Font(fontName string, size int, style string)
//style "" or "U" (underline)

TextColor(red int, green int, blue int) //Set Font color
GrayFill(grayScale float64) //Set grayScale for black font
TextColor(red int, green int, blue int) //Set Font color
GrayFill(grayScale float64) //Set grayScale for black font

- Text Draw
Cell(x float64, y float64, content string)
CellRight(x float64, y float64, w float64, content string) //Right Justify
Cell(x float64, y float64, content string)
CellRight(x float64, y float64, w float64, content string) //Right Justify

- Line Draw
LineType(ltype string, width float64)
//lineType "dashed" ,"dotted","straight" ""="straight"
GrayStroke(grayScale float64) //Set grayScale
LineH(x1 float64, y float64, x2 float64) // Horizontal Line
LineV(x float64, y1 float64, y2 float64) // Vertical line
Line(x1 float64, y1 float64, x2 float64, y2 float64)
LineType(ltype string, width float64) //lineType "dashed" ,"dotted","straight"
""="straight"
GrayStroke(grayScale float64) //Set grayScale
LineH(x1 float64, y float64, x2 float64) // Horizontal Line
LineV(x float64, y1 float64, y2 float64) // Vertical line
Line(x1 float64, y1 float64, x2 float64, y2 float64)

- Shape Draw
Rect(x1 float64, y1 float64, x2 float64, y2 float64)
Oval(x1 float64, y1 float64, x2 float64, y2 float64)
Rect(x1 float64, y1 float64, x2 float64, y2 float64)
Oval(x1 float64, y1 float64, x2 float64, y2 float64)

- Image Draw
Image(path string, x1 float64, y1 float64, x2 float64, y2 float64)
- Image Draw
Image(path string, x1 float64, y1 float64, x2 float64, y2 float64)

## Genarate Commands
- Execute(filename string)
Genarate PDF File.

- Execute(filename string)
Genarate PDF File.

- GetBytesPdf() (ret []byte)
Create byte stream
Create byte stream

## License
## License

goreport is released under the MIT License. It is copyrighted by Masanobu Shimura. (Gmail mikeshimura)
goreport is released under the MIT License. It is copyrighted by Masanobu
Shimura. (Gmail mikeshimura)

## Limitation
## Limitation

- Font style not allow B(bold) and I(italic).
- Line, Rect and Oval are Black and Gray only.
- Image file format is jpeg only.

## Sample program

[sample source](https://github.com/mikeshimura/goreport/tree/master/example)
[sample source](https://github.com/SlinSo/goreport/tree/master/example)

```go
package example

import (
gr "github.com/mikeshimura/goreport"
gr "github.com/SlinSo/goreport"
"strconv"
)

Expand Down
2 changes: 1 addition & 1 deletion example/complex1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package example

import (
//"fmt"
gr "github.com/mikeshimura/goreport"
gr "github.com/SlinSo/goreport"
//"io/ioutil"
"strconv"
//"strings"
Expand Down
2 changes: 1 addition & 1 deletion example/complex2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package example

import (
//"fmt"
gr "github.com/mikeshimura/goreport"
gr "github.com/SlinSo/goreport"
"time"
"unicode"
//"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion example/medium1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package example

import (
//"fmt"
gr "github.com/mikeshimura/goreport"
gr "github.com/SlinSo/goreport"
//"io/ioutil"
"strconv"
//"strings"
Expand Down
2 changes: 1 addition & 1 deletion example/simple1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package example

import (
//"fmt"
gr "github.com/mikeshimura/goreport"
gr "github.com/SlinSo/goreport"
//"io/ioutil"
"strconv"
//"strings"
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/SlinSo/goreport

go 1.15

require (
github.com/phpdave11/gofpdi v1.0.13 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/signintech/gopdf v0.9.12
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/phpdave11/gofpdi v1.0.8 h1:9HRg0Z0qDfWeMU7ska+YNQ13RHxTxqP5KTg/dBl4o7c=
github.com/phpdave11/gofpdi v1.0.8/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.13 h1:o61duiW8M9sMlkVXWlvP92sZJtGKENvW3VExs6dZukQ=
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/signintech/gopdf v0.9.12 h1:7Div65CTQVA6auXukSh3fa1pKgLct2cgKMpXQdtNlmQ=
github.com/signintech/gopdf v0.9.12/go.mod h1:MrARAC6LaOgbnV6vrC5885VuoWCXazhAqx8L8zmjYy4=
6 changes: 3 additions & 3 deletions goreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

"github.com/mikeshimura/dbflute/df"
"github.com/SlinSo/goreport/util"
)

const (
Expand Down Expand Up @@ -90,7 +90,7 @@ func (r *GoReport) ReplacePageTotal() {
return
}
lines := strings.Split(r.Converter.Text, "\n")
list := new(df.List)
list := new(util.List)
for i, line := range lines {
if len(line) < 8 {
continue
Expand All @@ -116,7 +116,7 @@ func (r *GoReport) ReplacePageTotal() {
}
r.Converter.Text = buf.String()
}
func (r *GoReport) getTotalPage(lineno int, list *df.List) int {
func (r *GoReport) getTotalPage(lineno int, list *util.List) int {
count := 0
page := 0
for i, l := range list.GetAsArray() {
Expand Down
2 changes: 1 addition & 1 deletion repmain/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/mikeshimura/goreport/example"
"github.com/SlinSo/goreport/example"
)

func main() {
Expand Down
37 changes: 37 additions & 0 deletions util/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package util

type List struct {
data []interface{}
}

func (s *List) Reset() {
s.data = make([]interface{}, 0, 100)
}

func (s *List) Add(value interface{}) {
if s.data == nil {
s.data = make([]interface{}, 0, 100)
}
if cap(s.data) < len(s.data)+1 {
newSlice := make([]interface{}, len(s.data), cap(s.data)*2)
copy(newSlice, s.data)
s.data = newSlice
}
s.data = append(s.data, value)
}
func (s *List) Get(i int) interface{} {
if i < len(s.data) {
return s.data[i]
} else {
return nil
}
}
func (s *List) Size() int {
return len(s.data)
}
func (s *List) GetAsArray() []interface{} {
if s.data == nil {
s.data = make([]interface{}, 0, 100)
}
return s.data
}

0 comments on commit 51f55ea

Please sign in to comment.