pdft

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: MIT Imports: 13 Imported by: 0

README

PDFT

PDFT is a Go library for creating PDF documents using existing PDFs as template. This library depend on gopdf.

Tested with PDF template files created from Libre office, Google Docs, Microsoft Word.

Usage

var pt pdft.PDFt
pdft.FontKeyword = "F"

err := pt.Open(pdfsource)
if err != nil {
	log.Println(err.Error())
	return
}

err = pt.AddFont("arial", "./arial.ttf")
if err != nil {
    log.Println(err.Error())
	return
}

err = pt.SetFont("arial", "", 14)
if err != nil {
    log.Println(err.Error())
	return
}

err = pt.Insert("Hi", 1, 10, 10, 100, 100, gopdf.Center|gopdf.Bottom)
if err != nil {
    log.Println(err.Error())
	return
}

err = pt.Save("./output.pdf")
if err != nil {
	log.Println(err.Error())
	return
}

Unit tests

go test -v ./...

Documentation

Index

Constants

View Source
const Bold = 2 //000010

Bold - font style bold

View Source
const Bottom = gopdf.Bottom //000001

Bottom bottom

View Source
const Center = gopdf.Center //010000

Center center

View Source
const Italic = 1 //000001

Italic - font style italic

View Source
const Left = gopdf.Left //001000

Left left

View Source
const Middle = gopdf.Middle //100000

Middle middle

View Source
const Regular = 0 //000000

Regular - font style regular

View Source
const Right = gopdf.Right //000010

Right right

View Source
const Top = gopdf.Top //000100

Top top

View Source
const Underline = 4 //000100

Underline - font style underline

Variables

View Source
var ErrAddSameFontName = errors.New("add same font name")

ErrAddSameFontName add same font name

View Source
var ErrCrawlResultValOfNotFound = errors.New("CrawlResult Val Of Not Found")

ErrCrawlResultValOfNotFound CrawlResult Val Of Not Found

View Source
var ErrFontNameNotFound = errors.New("font name not found")

ErrFontNameNotFound font name not found

View Source
var ErrWrongTypeOfVal = errors.New("wrong type of val")

ErrWrongTypeOfVal wrong type of val

View Source
var ErrorObjectIDNotFound = errors.New("Object ID not found")

ErrorObjectIDNotFound Object ID not found

View Source
var FontKeyword = "TT"

FontKeyword has TT as default value, can be set to F if PDF file has different font keyword

Functions

func PDFParse

func PDFParse(file io.Reader, outPdf *PDFData) error

PDFParse parse pdf

Types

type ContentLineStyle

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

ContentLineStyle set line width

type ContentText

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

ContentText text in pdf

type Contenter

type Contenter interface {
	// contains filtered or unexported methods
}

Contenter create content stream

type FuncKernOverride

type FuncKernOverride func(
	leftRune rune,
	rightRune rune,
	leftPair uint,
	rightPair uint,
	pairVal int16,
) int16

FuncKernOverride return your custome pair value

type FuncTextriseOverride

type FuncTextriseOverride func(
	leftRune rune,
	rightRune rune,
	fontsize int,
	allText string,
	currTextIndex int,
) float32

FuncTextriseOverride override text rise

type PDFData

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

PDFData pdf file data

func (*PDFData) Len

func (p *PDFData) Len() int

Len count

type PDFFontData

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

PDFFontData font data

func PDFParseFont

func PDFParseFont(path string, name string) (*PDFFontData, error)

PDFParseFont parse font

type PDFImageData

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

PDFImageData pdf img

type PDFObjData

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

PDFObjData byte of obj

type PDFObjPropertiesData

type PDFObjPropertiesData []PDFObjPropertyData

PDFObjPropertiesData array of PDFObjPropertyData

type PDFObjPropertyData

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

PDFObjPropertyData property of pdf obj

type PDFt

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

PDFt inject text to pdf

func (*PDFt) AddFont

func (i *PDFt) AddFont(name string, ttfpath string) error

AddFont add ttf font

func (*PDFt) DuplicatePageAfter added in v0.3.0

func (i *PDFt) DuplicatePageAfter(targetPageNumber, position int) error

DuplicatePageAfter ...

func (*PDFt) GetNumberOfPage added in v0.3.0

func (i *PDFt) GetNumberOfPage() int

GetNumberOfPage get number of page

func (*PDFt) Insert

func (i *PDFt) Insert(text string, pageNum int, x float64, y float64, w float64, h float64, align int) error

Insert insert text in to pdf

func (*PDFt) InsertImg

func (i *PDFt) InsertImg(img []byte, pageNum int, x float64, y float64, w float64, h float64) error

InsertImg insert img

func (*PDFt) InsertImgBase64

func (i *PDFt) InsertImgBase64(base64str string, pageNum int, x float64, y float64, w float64, h float64) error

InsertImgBase64 insert img base 64

func (*PDFt) KernOverride

func (i *PDFt) KernOverride(name string, fn FuncKernOverride) error

KernOverride override kerning

func (*PDFt) Open

func (i *PDFt) Open(filepath string) error

Open open pdf file

func (*PDFt) OpenFrom added in v0.3.0

func (i *PDFt) OpenFrom(r io.Reader) error

OpenFrom open pdf from io.Reader

func (*PDFt) RemovePage added in v0.3.0

func (i *PDFt) RemovePage(targetPageNumber int) error

RemovePage remove page at targetPageNumber

func (*PDFt) Save

func (i *PDFt) Save(filepath string) error

Save saves output to pdf file

func (*PDFt) SaveTo

func (i *PDFt) SaveTo(w io.Writer) error

SaveTo save pdf to io.Writer

func (*PDFt) SetFont

func (i *PDFt) SetFont(name string, style string, size int) error

SetFont set font

func (*PDFt) SetProtection

func (i *PDFt) SetProtection(
	permissions int,
	userPass []byte,
	ownerPass []byte,
) error

SetProtection set pdf protection

func (*PDFt) ShowCellBorder

func (i *PDFt) ShowCellBorder(isShow bool)

ShowCellBorder show cell of border

func (*PDFt) TextriseOverride

func (i *PDFt) TextriseOverride(name string, fn FuncTextriseOverride) error

TextriseOverride override text rise Text rise, Trise , specifies the distance, in unscaled text space units, to move the baseline up or down from its default location. Positive values of text rise move the baseline up. Adjustments to the baseline are useful for drawing superscripts or subscripts. The default location of the baseline can be restored by setting the text rise to 0.

type TrailerData

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

TrailerData trailer

type XrefData

type XrefData struct {
	N10Digit int    //nnnnnnnnnn
	G5Digit  int    //ggggg
	Keyword  string //x
}

XrefData nnnnnnnnnn ggggg x eol

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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