lnpdf

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 14 Imported by: 0

README

README

Specifications

  • data.jsonの値は文字列のみ(数値は不可、フォーマットした文字列)
  • AutoScale is not applicable to multiline text

What is this repository for?

以下をソースとしてpdfを生成する。

  • template.json
  • data.json
  • template.pdf (template.jsonにて指定)

※各ファイル名はパラメータで変更可能

Parameters

サンプル実行用パラメータ

  • -g draw grid (default fasle)
  • -b fill background (default false)
  • -s fill sample text (default false)
  • -t template json file name (default "./resources/sampleTemplate.json")
  • -d data source json file name (default "./resources/sampleData.json")
  • -p path of private key for signing (if need signature)
  • -c path of certification for signing (if need signature)
  • -h path of chain for signing (if need chain)
  • -o generate pdf file name (default "sample.pdf")

Formats

template json
s{
    "version" : "1.0",                              // pdf module version
    "orientation" : "landscape",                    // [landscape|portlait]
    "size" : "A4",                                  // size
    "image" : "millsheet.pdf",                       // background image pdf
    "styles" : {                                    // define styles 
        "default" : {                               // default style
            "fontFamily" : "xxxxx",             
            "fontSize" : 9,
            "color" : "#000",
            "underline" : false,
            "horizontalAlignment" : "left",
            "verticalAlignment" : "middle"
        },
        "default-numeric" : {
            "style" : "default",                    // base style
            "horizontalAlignment" : "right"
        },
        ...
    },
    "fields" : [                                    // define fields
        {                                           // simple field
            "dataSource" : "customer",              // data source(this must be value in data.json)
            "style" : "default",                    // style(from styles)
            "rect" : [                              // rect to draw field
                180, 100, 220, 12                   // [x, y, width, height]
            ]
        },
        ...
        {                                           // record field
            "dataSource" : "properties",            // data source(this must be array in data.json)
            "rect" : [                              // rect to draw records
                140, 293, 263, 90
            ],
            "record" : {                            // define as record
                "direction" : "x",                  // record direction
                "size" : [                          // size to draw record
                    52.6, 90                        // [x, y]
                ],
                "fields" : [                        // define fields on record
                    {
                        "dataSource" : "labelEn",   // data source(this must be records' member in data.json)
                        "style" : "default",        // style(from styles)
                        "rect" : [                  // offset rect in record
                            0, 0, 52.6, 15
                        ]
                    },
                    {
                        "dataSource" : "max",
                        "style" : "default",
                        "rect" : [
                            0, 15, 52.6, 15         // offset rect in record
                        ]
                    },
                    {
                        "dataSource" : "unit",
                        "style" : "default",
                        "rect" : [
                            0, 30, 52.6, 15         // offset rect in record
                        ]
                    },
                    ...
                ]
            }
        },
        ...
    ]
}
data json
{
    "customer" : "Mill Cert Sample Customer",
    ...
    "properties" : [
        {
            "labelEn" : "Yield Strength",
            "max" : "245.000",
            "unit" : "N/m ㎡"
        },
        {
            "labelEn" : "Tensile Strength",
            "max" : "640.500",
            "unit" : "N/m ㎡"
        },
        ...
    ]
}```

Documentation

Index

Constants

View Source
const (
	Portlait  = TypeOrientation("portlait")
	Landscape = TypeOrientation("landscape")
)
View Source
const (
	A1 = TypePaperSize("A1")
	A2 = TypePaperSize("A2")
	A3 = TypePaperSize("A3")
	A4 = TypePaperSize("A4")
	A5 = TypePaperSize("A5")
	//	B1 = TypePaperSize("B1")
	//	B2 = TypePaperSize("B2")
	//	B3 = TypePaperSize("B3")
	B4 = TypePaperSize("B4")
	B5 = TypePaperSize("B5")
)
View Source
const (
	Crop      = StyleOverflow("crop")
	Overflow  = StyleOverflow("overflow")
	Autoscale = StyleOverflow("autoscale")
)
View Source
const (
	Left   = StyleHorizontalAlignment("left")
	Center = StyleHorizontalAlignment("center")
	Right  = StyleHorizontalAlignment("right")
)
View Source
const (
	Top    = StyleVerticalAlignment("top")
	Middle = StyleVerticalAlignment("middle")
	Bottom = StyleVerticalAlignment("bottom")
)

Variables

This section is empty.

Functions

func Copy

func Copy(srcPath *string, destPath *string)

func Sign

func Sign(pdfPath *string, privateKeyPath *string, certificatePath *string, chainPath *string, signingInfo *SigningInfo)

func ToPath

func ToPath(path *string) string

./path/to -> /[working directory]/path/to path/to -> path/to /path/to -> /path/to

Types

type Builder

type Builder struct {
	DrawGrid       bool
	FillBackground bool
	FillSampleText bool
	TemplatePath   string
	DataSourcePath string
}

func (Builder) Build

func (this Builder) Build() *Pdf

type FieldEntity

type FieldEntity struct {
	DataSource string
	Style      string
	Rect       [4]float64
	Record     RecordEntity
}

type Hex

type Hex string

func (*Hex) ToRGB

func (this *Hex) ToRGB() (*RGB, error)

type Pdf

type Pdf struct {
	gopdf.GoPdf

	Styles *map[string]Style
	Rect   Rect
}

gopdf.GoPdf structure with style

func (*Pdf) AddFont

func (this *Pdf) AddFont(family string, path string) error

add .ttf font

func (*Pdf) AddStyles

func (this *Pdf) AddStyles(styles *map[string]StyleEntity)

func (*Pdf) DrawText

func (this *Pdf) DrawText(rect *Rect, styleName *string, text *string)

draw text within rect with style

func (*Pdf) FillText

func (this *Pdf) FillText(rect *Rect, styleName *string)

draw sample text within rect

func (*Pdf) GetPaperSize

func (this *Pdf) GetPaperSize(paperSize *string, orientation *string) *gopdf.Rect

func (*Pdf) Output

func (this *Pdf) Output(path *string)

type PdfEntity

type PdfEntity struct {
	Version     string
	Orientation string
	Size        string
	Image       string
	Fonts       map[string]string
	Styles      map[string]StyleEntity
	Fields      []FieldEntity
}

func (*PdfEntity) FromFile

func (this *PdfEntity) FromFile(path *string)

type RGB

type RGB struct {
	Red   uint8
	Green uint8
	Blue  uint8
}

func Hex2RGB

func Hex2RGB(hex *Hex) (*RGB, error)

func (*RGB) FromArray

func (this *RGB) FromArray(uints []uint8)

func (*RGB) ToArray

func (this *RGB) ToArray() []uint8

type RecordEntity

type RecordEntity struct {
	Direction string
	Size      []float64
	Fields    []RecordFieldEntity
}

type RecordFieldEntity

type RecordFieldEntity struct {
	DataSource string
	Style      string
	Rect       [4]float64
}

type Rect

type Rect struct {
	X float64
	Y float64
	W float64
	H float64
}

func (*Rect) FromArray

func (this *Rect) FromArray(rect *[4]float64)

func (*Rect) ToGoRect

func (this *Rect) ToGoRect() gopdf.Rect

type SigningInfo

type SigningInfo struct {
	Name        string
	Location    string
	Reason      string
	ContactInfo string
	TsrUrl      string
}

type Style

type Style struct {
	FontFamily          string
	FontSize            float64
	Color               string
	Underline           bool
	HorizontalAlignment StyleHorizontalAlignment
	VerticalAlignment   StyleVerticalAlignment
	Overflow            StyleOverflow
	Multiline           bool
}

type StyleEntity

type StyleEntity struct {
	Style               *string
	FontFamily          *string
	FontSize            *float64
	Color               *string
	Underline           *bool
	HorizontalAlignment *string
	VerticalAlignment   *string
	Format              *string
	Multiline           *bool
	Overflow            *string
}

type StyleHorizontalAlignment

type StyleHorizontalAlignment string

type StyleOverflow

type StyleOverflow string

type StyleVerticalAlignment

type StyleVerticalAlignment string

type TypeOrientation

type TypeOrientation string

type TypePaperSize

type TypePaperSize string

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL