gopdf

package module
v0.0.0-...-14f9c33 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2015 License: MIT Imports: 9 Imported by: 0

README

gopdf

A simple library for generating PDF written in Go lang.

Use fpdfGo to generate fonts.
Use fontmaker to generate fonts.
Sample code here

####Installation

go get github.com/signintech/gopdf

####Example

package main
import (
  "fmt"
  iconv "github.com/djimenez/iconv-go"
  "github.com/signintech/gopdf"
  "github.com/signintech/gopdf/fonts"
)

func main() {

  pdf := gopdf.GoPdf{}
  pdf.Start(gopdf.Config{Unit: "pt", PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //A4
  pdf.AddFont("THSarabunPSK",new(fonts.THSarabun),"THSarabun.z")
  pdf.AddFont("Loma",new(fonts.Loma),"Loma.z")
  pdf.AddPage()
  pdf.SetFont("THSarabunPSK","B",14)
  pdf.Cell(nil,   ToCp874("Hello world  = สวัสดี โลก in thai"))
  pdf.WritePdf("x.pdf")
  fmt.Println("Done...")
}

func ToCp874(str string) string{
  str, _ = iconv.ConvertString( str, "utf-8", "cp874") 
  return  str
}
  

gopdf / fontmaker

fontmaker is a font making tool for gopdf.

####Build fontmaker ######open terminal

$ cd {GOPATH}/src/github.com/signintech/gopdf/fontmaker

$ go build

####Usage:

fontmaker encoding  map_folder  font_file  output_folder

####Example: ######run command

fontmaker  cp874  /gopath/github.com/signintech/gopdf/fontmaker/map   ../ttf/Loma.ttf  ./tmp 

######result

Save Z file at ./tmp/Loma.z.
Save GO file at ./tmp/Loma.font.go.
Finish.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chr

func Chr(n int) byte

func ContentObj_CalTextHeight

func ContentObj_CalTextHeight(fontsize int) float64

cal text height

func FontConvertHelper_Cw2Str

func FontConvertHelper_Cw2Str(cw FontCw) string

func StrHelper_GetStringWidth

func StrHelper_GetStringWidth(str string, fontSize int, ifont IFont) float64

func ToByte

func ToByte(chr string) byte

Types

type BasicObj

type BasicObj struct {
	Data string
	// contains filtered or unexported fields
}

func (*BasicObj) Build

func (me *BasicObj) Build()

func (*BasicObj) GetObjBuff

func (me *BasicObj) GetObjBuff() *bytes.Buffer

func (*BasicObj) GetType

func (me *BasicObj) GetType() string

func (*BasicObj) Init

func (me *BasicObj) Init(funcGetRoot func() *GoPdf)

type CatalogObj

type CatalogObj struct {
	// contains filtered or unexported fields
}

func (*CatalogObj) Build

func (me *CatalogObj) Build()

func (*CatalogObj) GetObjBuff

func (me *CatalogObj) GetObjBuff() *bytes.Buffer

func (*CatalogObj) GetType

func (me *CatalogObj) GetType() string

func (*CatalogObj) Init

func (me *CatalogObj) Init(funcGetRoot func() *GoPdf)

type Config

type Config struct {
	//pt , mm , cm , in
	Unit     string
	PageSize Rect
	K        float64
}

type ContentObj

type ContentObj struct {
	// contains filtered or unexported fields
}

func (*ContentObj) AppendStream

func (me *ContentObj) AppendStream(rectangle *Rect, text string)

func (*ContentObj) AppendStreamImage

func (me *ContentObj) AppendStreamImage(index int, x float64, y float64, rect *Rect)

func (*ContentObj) AppendStreamLine

func (me *ContentObj) AppendStreamLine(x1 float64, y1 float64, x2 float64, y2 float64)

func (*ContentObj) AppendStreamSetLineWidth

func (me *ContentObj) AppendStreamSetLineWidth(w float64)

func (*ContentObj) AppendUnderline

func (me *ContentObj) AppendUnderline(startX float64, y float64, endX float64, endY float64, text string)

func (*ContentObj) Build

func (me *ContentObj) Build()

func (*ContentObj) GetObjBuff

func (me *ContentObj) GetObjBuff() *bytes.Buffer

func (*ContentObj) GetType

func (me *ContentObj) GetType() string

func (*ContentObj) Init

func (me *ContentObj) Init(funcGetRoot func() *GoPdf)

type Current

type Current struct {
	X float64
	Y float64

	//font
	IndexOfFontObj int
	CountOfFont    int
	CountOfL       int

	Font_Size      int
	Font_Style     string
	Font_IFont     IFont
	Font_FontCount int

	//page
	IndexOfPageObj int

	//img
	CountOfImg int
	//cache of image in pdf file
	ImgCaches []ImageCache
}

type EmbedFontObj

type EmbedFontObj struct {
	Data string
	// contains filtered or unexported fields
}

func (*EmbedFontObj) Build

func (me *EmbedFontObj) Build()

func (*EmbedFontObj) GetObjBuff

func (me *EmbedFontObj) GetObjBuff() *bytes.Buffer

func (*EmbedFontObj) GetType

func (me *EmbedFontObj) GetType() string

func (*EmbedFontObj) Init

func (me *EmbedFontObj) Init(funcGetRoot func() *GoPdf)

func (*EmbedFontObj) SetFont

func (me *EmbedFontObj) SetFont(font IFont, zfontpath string)

type EncodingObj

type EncodingObj struct {
	// contains filtered or unexported fields
}

func (*EncodingObj) Build

func (me *EncodingObj) Build()

func (*EncodingObj) GetFont

func (me *EncodingObj) GetFont() IFont

func (*EncodingObj) GetObjBuff

func (me *EncodingObj) GetObjBuff() *bytes.Buffer

func (*EncodingObj) GetType

func (me *EncodingObj) GetType() string

func (*EncodingObj) Init

func (me *EncodingObj) Init(funcGetRoot func() *GoPdf)

func (*EncodingObj) SetFont

func (me *EncodingObj) SetFont(font IFont)

type FontCw

type FontCw map[byte]int

type FontDescItem

type FontDescItem struct {
	Key string
	Val string
}

type FontDescriptorObj

type FontDescriptorObj struct {
	// contains filtered or unexported fields
}

func (*FontDescriptorObj) Build

func (me *FontDescriptorObj) Build()

func (*FontDescriptorObj) GetFont

func (me *FontDescriptorObj) GetFont() IFont

func (*FontDescriptorObj) GetObjBuff

func (me *FontDescriptorObj) GetObjBuff() *bytes.Buffer

func (*FontDescriptorObj) GetType

func (me *FontDescriptorObj) GetType() string

func (*FontDescriptorObj) Init

func (me *FontDescriptorObj) Init(funcGetRoot func() *GoPdf)

func (*FontDescriptorObj) SetFont

func (me *FontDescriptorObj) SetFont(font IFont)

func (*FontDescriptorObj) SetFontFileObjRelate

func (me *FontDescriptorObj) SetFontFileObjRelate(relate string)

type FontObj

type FontObj struct {
	Family string
	//Style string
	//Size int
	IsEmbedFont bool

	Font        IFont
	CountOfFont int
	// contains filtered or unexported fields
}

func (*FontObj) Build

func (me *FontObj) Build()

func (*FontObj) GetObjBuff

func (me *FontObj) GetObjBuff() *bytes.Buffer

func (*FontObj) GetType

func (me *FontObj) GetType() string

func (*FontObj) Init

func (me *FontObj) Init(funcGetRoot func() *GoPdf)

func (*FontObj) SetIndexObjEncoding

func (me *FontObj) SetIndexObjEncoding(index int)

func (*FontObj) SetIndexObjFontDescriptor

func (me *FontObj) SetIndexObjFontDescriptor(index int)

func (*FontObj) SetIndexObjWidth

func (me *FontObj) SetIndexObjWidth(index int)

type GoPdf

type GoPdf struct {

	//ต่ำแหน่งปัจจุบัน
	Curr Current
	// contains filtered or unexported fields
}

func (*GoPdf) AddFont

func (me *GoPdf) AddFont(family string, ifont IFont, zfontpath string)

func (*GoPdf) AddPage

func (me *GoPdf) AddPage()

เพิ่ม page

func (*GoPdf) Br

func (me *GoPdf) Br(h float64)

ขึ้นบรรทัดใหม่

func (*GoPdf) Cell

func (me *GoPdf) Cell(rectangle *Rect, text string)

สร้าง cell ของ text Note that this has no effect on Rect.H pdf (now). Fix later :-)

func (*GoPdf) GetBytesPdf

func (me *GoPdf) GetBytesPdf() []byte

get bytes of pdf file

func (*GoPdf) GetX

func (me *GoPdf) GetX() float64

func (*GoPdf) GetY

func (me *GoPdf) GetY() float64

func (*GoPdf) Image

func (me *GoPdf) Image(picPath string, x float64, y float64, rect *Rect)

func (*GoPdf) Line

func (me *GoPdf) Line(x1 float64, y1 float64, x2 float64, y2 float64)

วาดเส้น

func (*GoPdf) SetFont

func (me *GoPdf) SetFont(family string, style string, size int)

set font

func (*GoPdf) SetLeftMargin

func (me *GoPdf) SetLeftMargin(margin float64)

func (*GoPdf) SetLineWidth

func (me *GoPdf) SetLineWidth(width float64)

func (*GoPdf) SetTopMargin

func (me *GoPdf) SetTopMargin(margin float64)

func (*GoPdf) SetX

func (me *GoPdf) SetX(x float64)

func (*GoPdf) SetY

func (me *GoPdf) SetY(y float64)

func (*GoPdf) Start

func (me *GoPdf) Start(config Config)

เริ่ม

func (*GoPdf) WritePdf

func (me *GoPdf) WritePdf(pdfPath string)

create pdf file

type IFont

type IFont interface {
	Init()
	GetType() string
	GetName() string
	GetDesc() []FontDescItem
	GetUp() int
	GetUt() int
	GetCw() FontCw
	GetEnc() string
	GetDiff() string
	GetOriginalsize() int

	SetFamily(family string)
	GetFamily() string
}

type IObj

type IObj interface {
	Init(func() *GoPdf)
	GetType() string
	GetObjBuff() *bytes.Buffer
	//สร้าง ข้อมูลใน pdf
	Build()
}

type ImageCache

type ImageCache struct {
	Path  string
	Index int
}

type ImageObj

type ImageObj struct {
	// contains filtered or unexported fields
}

func (*ImageObj) Build

func (me *ImageObj) Build()

func (*ImageObj) GetObjBuff

func (me *ImageObj) GetObjBuff() *bytes.Buffer

func (*ImageObj) GetRect

func (me *ImageObj) GetRect() *Rect

func (*ImageObj) GetType

func (me *ImageObj) GetType() string

func (*ImageObj) Init

func (me *ImageObj) Init(funcGetRoot func() *GoPdf)

func (*ImageObj) SetImagePath

func (me *ImageObj) SetImagePath(path string)

type PageObj

type PageObj struct {
	Contents        string
	ResourcesRelate string
	// contains filtered or unexported fields
}

func (*PageObj) Build

func (me *PageObj) Build()

func (*PageObj) GetObjBuff

func (me *PageObj) GetObjBuff() *bytes.Buffer

func (*PageObj) GetType

func (me *PageObj) GetType() string

func (*PageObj) Init

func (me *PageObj) Init(funcGetRoot func() *GoPdf)

type PagesObj

type PagesObj struct {
	PageCount int
	Kids      string
	// contains filtered or unexported fields
}

func (*PagesObj) Build

func (me *PagesObj) Build()

func (*PagesObj) GetObjBuff

func (me *PagesObj) GetObjBuff() *bytes.Buffer

func (*PagesObj) GetType

func (me *PagesObj) GetType() string

func (*PagesObj) Init

func (me *PagesObj) Init(funcGetRoot func() *GoPdf)

func (*PagesObj) Test

func (me *PagesObj) Test()

type ProcSetObj

type ProcSetObj struct {

	//Font
	Realtes     RelateFonts
	RealteXobjs RealteXobjects
	// contains filtered or unexported fields
}

func (*ProcSetObj) Build

func (me *ProcSetObj) Build()

func (*ProcSetObj) GetObjBuff

func (me *ProcSetObj) GetObjBuff() *bytes.Buffer

func (*ProcSetObj) GetType

func (me *ProcSetObj) GetType() string

func (*ProcSetObj) Init

func (me *ProcSetObj) Init(funcGetRoot func() *GoPdf)

type RealteXobject

type RealteXobject struct {
	IndexOfObj int
}

type RealteXobjects

type RealteXobjects []RealteXobject

type Rect

type Rect struct {
	W float64
	H float64
}

type RelateFont

type RelateFont struct {
	Family string
	//etc /F1
	CountOfFont int
	//etc  5 0 R
	IndexOfObj int
}

type RelateFonts

type RelateFonts []RelateFont

func (*RelateFonts) IsContainsFamily

func (me *RelateFonts) IsContainsFamily(family string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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