gopdf

package module
v0.0.0-...-ef70d99 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 25 Imported by: 1

README

gopdf

gopdf is a simple library for generating PDF document written in Go lang.

A minimum version of Go 1.13 is required.

Features
  • Unicode subfont embedding. (Chinese, Japanese, Korean, etc.)
  • Draw line, oval, rect, curve
  • Draw image ( jpg, png )
    • Set image mask
  • Password protection
  • Font kerning

Installation

go get -u github.com/ananrafs/gopdf
Print text

package main
import (
	"log"
	"github.com/ananrafs/gopdf"
)

func main() {

	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{ PageSize: *gopdf.PageSizeA4 })
	pdf.AddPage()
	err := pdf.AddTTFFont("wts11", "../ttf/wts11.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.SetFont("wts11", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.Cell(nil, "您好")
	pdf.WritePdf("hello.pdf")

}

Set text color using RGB color model
pdf.SetTextColor(156, 197, 140)
pdf.Cell(nil, "您好")
Set text color using CMYK color model
pdf.SetTextColorCMYK(0, 6, 14, 0)
pdf.Cell
Image

package main
import (
	"log"
	"github.com/ananrafs/gopdf"
)

func main() {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4 })
	pdf.AddPage()
	var err error
	err = pdf.AddTTFFont("loma", "../ttf/Loma.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	pdf.Image("../imgs/gopher.jpg", 200, 50, nil) //print image
	err = pdf.SetFont("loma", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}
	pdf.SetXY(250, 200) //move current location
	pdf.Cell(nil, "gopher and gopher") //print text

	pdf.WritePdf("image.pdf")
}

package main

import (
	"log"
	"github.com/ananrafs/gopdf"
)

func main()  {
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{ PageSize: *gopdf.PageSizeA4 }) //595.28, 841.89 = A4
	pdf.AddPage()
	err := pdf.AddTTFFont("times", "./test/res/times.ttf")
	if err != nil {
		log.Print(err.Error())
		return
	}

	err = pdf.SetFont("times", "", 14)
	if err != nil {
		log.Print(err.Error())
		return
	}

	pdf.SetXY(30, 40)
	pdf.Text("Link to example.com")
	pdf.AddExternalLink("http://example.com/", 27.5, 28, 125, 15)

	pdf.SetXY(30, 70)
	pdf.Text("Link to second page")
	pdf.AddInternalLink("anchor", 27.5, 58, 120, 15)

	pdf.AddPage()
	pdf.SetXY(30, 100)
	pdf.SetAnchor("anchor")
	pdf.Text("Anchor position")

	pdf.WritePdf("hello.tmp.pdf")

}

package main

import (
    "log"
    "github.com/ananrafs/gopdf"
)

func main() {
    pdf := gopdf.GoPdf{}
    pdf.Start(gopdf.Config{ PageSize: *gopdf.PageSizeA4 }) //595.28, 841.89 = A4

    err := pdf.AddTTFFont("LiberationSerif-Regular", "./test/res/LiberationSerif-Regular.ttf")
    if err != nil {
        log.Print(err.Error())
        return
    }

    err = pdf.SetFont("LiberationSerif-Regular", "", 14)
    if err != nil {
        log.Print(err.Error())
        return
    }

    pdf.AddHeader(func() {
        pdf.SetY(5)
        pdf.Cell(nil, "header")
    })
    pdf.AddFooter(func() {
        pdf.SetY(825)
        pdf.Cell(nil, "footer")
    })

    pdf.AddPage()
    pdf.SetY(400)
    pdf.Text("page 1 content")
    pdf.AddPage()
    pdf.SetY(400)
    pdf.Text("page 2 content")

    pdf.WritePdf("header-footer.tmp.pdf")

}

Draw line
pdf.SetLineWidth(2)
pdf.SetLineType("dashed")
pdf.Line(10, 30, 585, 30)
Draw oval
pdf.SetLineWidth(1)
pdf.Oval(100, 200, 500, 500)
Draw polygon
pdf.SetStrokeColor(255, 0, 0)
pdf.SetLineWidth(2)
pdf.SetFillColor(0, 255, 0)
pdf.Polygon([]gopdf.Point{{X: 10, Y: 30}, {X: 585, Y: 200}, {X: 585, Y: 250}}, "DF")
Draw rectangle with round corner
pdf.SetStrokeColor(255, 0, 0)
pdf.SetLineWidth(2)
pdf.SetFillColor(0, 255, 0)
err := pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)
if err != nil {
	return err
}
Draw rectangle with round corner using CMYK color model
pdf.SetStrokeColorCMYK(88, 49, 0, 0)
pdf.SetLineWidth(2)
pdf.SetFillColorCMYK(0, 5, 89, 0)
err := pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)
if err != nil {
	return err
}
Rotation text or image
pdf.SetXY(100, 100)
pdf.Rotate(270.0, 100.0, 100.0)
pdf.Text("Hello...")
pdf.RotateReset() //reset
Set transparency

Read about transparency in pdf (page 320, section 11)

// alpha - value of transparency, can be between `0` and `1`
// blendMode - default value is `/Normal` - read about [blendMode and kinds of its](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf) `(page 325, section 11.3.5)`

transparency := Transparency{
	Alpha: 0.5,
	BlendModeType: "",
}
pdf.SetTransparency(transparency Transparency)
Password protection
package main

import (
	"log"

	"github.com/ananrafs/gopdf"
)


func main() {

	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{
		PageSize: *gopdf.PageSizeA4, //595.28, 841.89 = A4
		Protection: gopdf.PDFProtectionConfig{
			UseProtection: true,
			Permissions: gopdf.PermissionsPrint | gopdf.PermissionsCopy | gopdf.PermissionsModify,
			OwnerPass:   []byte("123456"),
			UserPass:    []byte("123456789")},
	})

	pdf.AddPage()
	pdf.AddTTFFont("loma", "../ttf/loma.ttf")
	pdf.Cell(nil,"Hi")
	pdf.WritePdf("protect.pdf")
}

Import existing PDF

Import existing PDF power by package gofpdi created by @phpdave11 (thank you 😄)

package main

import (
        "github.com/ananrafs/gopdf"
        "io"
        "net/http"
        "os"
)

func main() {
        var err error

        // Download a Font
        fontUrl := "https://github.com/google/fonts/raw/master/ofl/daysone/DaysOne-Regular.ttf"
        if err = DownloadFile("example-font.ttf", fontUrl); err != nil {
            panic(err)
        }

        // Download a PDF
        fileUrl := "https://tcpdf.org/files/examples/example_012.pdf"
        if err = DownloadFile("example-pdf.pdf", fileUrl); err != nil {
            panic(err)
        }

        pdf := gopdf.GoPdf{}
        pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}}) //595.28, 841.89 = A4

        pdf.AddPage()

        err = pdf.AddTTFFont("daysone", "example-font.ttf")
        if err != nil {
            panic(err)
        }

        err = pdf.SetFont("daysone", "", 20)
        if err != nil {
            panic(err)
        }

        // Color the page
        pdf.SetLineWidth(0.1)
        pdf.SetFillColor(124, 252, 0) //setup fill color
        pdf.RectFromUpperLeftWithStyle(50, 100, 400, 600, "FD")
        pdf.SetFillColor(0, 0, 0)

        pdf.SetXY(50, 50)
        pdf.Cell(nil, "Import existing PDF into GoPDF Document")

        // Import page 1
        tpl1 := pdf.ImportPage("example-pdf.pdf", 1, "/MediaBox")

        // Draw pdf onto page
        pdf.UseImportedTemplate(tpl1, 50, 100, 400, 0)

        pdf.WritePdf("example.pdf")

}

// DownloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func DownloadFile(filepath string, url string) error {
        // Get the data
        resp, err := http.Get(url)
        if err != nil {
            return err
        }
        defer resp.Body.Close()

        // Create the file
        out, err := os.Create(filepath)
        if err != nil {
            return err
        }
        defer out.Close()

        // Write the body to file
        _, err = io.Copy(out, resp.Body)
        return err
}

Possible to set Trim-box
package main

import (
	"log"

	"github.com/ananrafs/gopdf"
)

func main() {

    pdf := gopdf.GoPdf{}
    mm6ToPx := 22.68

    // Base trim-box
    pdf.Start(gopdf.Config{
        PageSize: *gopdf.PageSizeA4, //595.28, 841.89 = A4
        TrimBox: gopdf.Box{Left: mm6ToPx, Top: mm6ToPx, Right: 595 - mm6ToPx, Bottom: 842 - mm6ToPx},
    })

    // Page trim-box
    opt := gopdf.PageOption{
        PageSize: gopdf.PageSizeA4, //595.28, 841.89 = A4
        TrimBox: &gopdf.Box{Left: mm6ToPx, Top: mm6ToPx, Right: 595 - mm6ToPx, Bottom: 842 - mm6ToPx},
    }
    pdf.AddPageWithOption(opt)

    if err := pdf.AddTTFFont("wts11", "../ttf/wts11.ttf"); err != nil {
        log.Print(err.Error())
        return
    }

    if err := pdf.SetFont("wts11", "", 14); err != nil {
        log.Print(err.Error())
        return
    }

    pdf.Cell(nil,"Hi")
    pdf.WritePdf("hello.pdf")
}

Placeholder.

this function(s) made for experimental. There may be changes in the future.

With the placeholder function(s), you can create a placeholder to define a position. To make room for text to be add later.

There are 2 related function(s):

  • PlaceHolderText(...) used to create a placeholder to fill in text later.
  • FillInPlaceHoldText(...) used for filling in text into the placeholder that was created with PlaceHolderText.

Use case: For example, when you want to print the "total number of pages" on every page in pdf file, but you don't know the "total number of pages" until you have created all the pages. You can use func PlaceHolderText to create the point where you want "total number of pages" to be printed. And then when you have created all the pages so you know the "total number of pages", you call FillInPlaceHoldText(...). This function will take the text (in this case, text is "total number of pages") replace at the point that been created since func PlaceHolderText.

func main(){
    	pdf := GoPdf{}
	pdf.Start(Config{PageSize: Rect{W: 595.28, H: 841.89}}) 
	pdf.AddTTFFont("LiberationSerif-Regular", "LiberationSerif-Regular.ttf")
	pdf.SetFont("LiberationSerif-Regular", "", 14) }

	for i := 0; i < 5; i++ {
		pdf.AddPage()
        	pdf.Br(20)
        	//create PlaceHolder
		err = pdf.PlaceHolderText("totalnumber", 30)
		if err != nil {
			log.Print(err.Error())
			return
		}

	}

    	//fillin text to PlaceHolder
	err = pdf.FillInPlaceHoldText("totalnumber",fmt.Sprintf("%d", 5), Left)
	if err != nil {
		log.Print(err.Error())
		return
	}

	pdf.WritePdf("placeholder_text.pdf")
}

visit https://github.com/oneplus1000/gopdfsample for more samples.

Documentation

Index

Examples

Constants

View Source
const (
	UnitUnset = iota // No units were set, when conversion is called on nothing will happen
	UnitPT           // Points
	UnitMM           // Millimeters
	UnitCM           // Centimeters
	UnitIN           // Inches
	UnitPX           // Pixels

)

The units that can be used in the document

View Source
const (
	Unit_Unset = UnitUnset // No units were set, when conversion is called on nothing will happen
	Unit_PT    = UnitPT    // Points
	Unit_MM    = UnitMM    // Millimeters
	Unit_CM    = UnitCM    // Centimeters
	Unit_IN    = UnitIN    // Inches
	Unit_PX    = UnitPX    // Pixels
)

The units that can be used in the document (for backward compatibility) Deprecated: Use UnitUnset,UnitPT,UnitMM,UnitCM,UnitIN instead

View Source
const (
	//PermissionsPrint setProtection print
	PermissionsPrint = 4
	//PermissionsModify setProtection modify
	PermissionsModify = 8
	//PermissionsCopy setProtection copy
	PermissionsCopy = 16
	//PermissionsAnnotForms setProtection  annot-forms
	PermissionsAnnotForms = 32
)
View Source
const (
	SMaskAlphaSubtype      = "/Alpha"
	SMaskLuminositySubtype = "/Luminosity"
)
View Source
const AllBorders = 15 //001111

AllBorders allborders

View Source
const Bold = 2 //000010

Bold - font style bold

View Source
const Bottom = 1 //000001

Bottom bottom

View Source
const Center = 16 //010000

Center center

View Source
const ContentTypeCell = 0

ContentTypeCell cell

View Source
const ContentTypeText = 1

ContentTypeText text

View Source
const DefaultAplhaValue = 1
View Source
const (
	DeviceGray = "DeviceGray"
)
View Source
const Italic = 1 //000001

Italic - font style italic

View Source
const Left = 8 //001000

Left left

View Source
const Middle = 32 //100000

Middle middle

View Source
const Regular = 0 //000000

Regular - font style regular

View Source
const Right = 2 //000010

Right right

View Source
const Top = 4 //000100

Top top

View Source
const Underline = 4 //000100

Underline - font style underline

Variables

View Source
var (
	// DefaultBreakOption will cause the text to break mid-word without any separator suffixes.
	DefaultBreakOption = BreakOption{
		Mode:           BreakModeStrict,
		BreakIndicator: 0,
		Separator:      "",
	}
)
View Source
var EntrySelectors = []int{
	0, 0, 1, 1, 2, 2,
	2, 2, 3, 3, 3, 3,
	3, 3, 3, 3, 4, 4,
	4, 4, 4, 4, 4, 4,
	4, 4, 4, 4, 4, 4, 4,
}

EntrySelectors entry selectors

View Source
var ErrCharNotFound = errors.New("char not found")

ErrCharNotFound char not found

View Source
var ErrContentTypeNotFound = errors.New("contentType not found")
View Source
var ErrEmptyString = errors.New("empty string")
View Source
var ErrGlyphNotFound = errors.New("glyph not found")

ErrGlyphNotFound font file not contain glyph

View Source
var ErrInvalidRectangleCoordinates = errors.New("Invalid coordinates for the rectangle")
View Source
var ErrInvalidRectangleRadius = errors.New("Radius length cannot exceed rectangle height or width")
View Source
var ErrMissingFontFamily = errors.New("font family not found")
View Source
var ErrNotSupportShortIndexYet = errors.New("not support none short index yet")

ErrNotSupportShortIndexYet not support none short index yet

View Source
var ErrUndefinedCacheContentImage = errors.New("cacheContentImage is undefined")
View Source
var PageSize10x14 = &Rect{W: 720, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSize10x14 page format

View Source
var PageSizeA0 = &Rect{W: 2384, H: 3371, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA0 page format

View Source
var PageSizeA1 = &Rect{W: 1685, H: 2384, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA1 page format

View Source
var PageSizeA2 = &Rect{W: 1190, H: 1684, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA2 page format

View Source
var PageSizeA3 = &Rect{W: 842, H: 1190, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA3 page format

View Source
var PageSizeA4 = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4 page format

View Source
var PageSizeA4Landscape = &Rect{W: 842, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4Landscape page format

View Source
var PageSizeA4Small = &Rect{W: 595, H: 842, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA4Small page format

View Source
var PageSizeA5 = &Rect{W: 420, H: 595, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeA5 page format

View Source
var PageSizeB4 = &Rect{W: 729, H: 1032, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeB4 page format

View Source
var PageSizeB5 = &Rect{W: 516, H: 729, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeB5 page format

View Source
var PageSizeExecutive = &Rect{W: 540, H: 720, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeExecutive page format

View Source
var PageSizeFolio = &Rect{W: 612, H: 936, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeFolio page format

View Source
var PageSizeLedger = &Rect{W: 1224, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLedger page format

View Source
var PageSizeLegal = &Rect{W: 612, H: 1008, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLegal page format

View Source
var PageSizeLetter = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLetter page format

View Source
var PageSizeLetterSmall = &Rect{W: 612, H: 792, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeLetterSmall page format

View Source
var PageSizeQuarto = &Rect{W: 610, H: 780, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeQuarto page format

View Source
var PageSizeStatement = &Rect{W: 396, H: 612, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeStatement page format

View Source
var PageSizeTabloid = &Rect{W: 792, H: 1224, unitOverride: defaultUnitConfig{Unit: UnitPT}}

PageSizeTabloid page format

Functions

func CheckSum

func CheckSum(data []byte) uint

CheckSum check sum

func ContentObjCalTextHeight

func ContentObjCalTextHeight(fontsize int) float64

ContentObjCalTextHeight : calculates height of text.

func ContentObjCalTextHeightPrecise

func ContentObjCalTextHeightPrecise(fontsize float64) float64

ContentObjCalTextHeightPrecise : like ContentObjCalTextHeight, but fontsize float64

func CreateEmbeddedFontSubsetName

func CreateEmbeddedFontSubsetName(name string) string

CreateEmbeddedFontSubsetName create Embedded font (subset font) name

func DefaultOnGlyphNotFoundSubstitute

func DefaultOnGlyphNotFoundSubstitute(r rune) rune

func DesignUnitsToPdf

func DesignUnitsToPdf(val int, unitsPerEm uint) int

DesignUnitsToPdf convert unit

func FontConvertHelperCw2Str

func FontConvertHelperCw2Str(cw FontCw) string

FontConvertHelperCw2Str converts main ASCII characters of a FontCW to a string.

func FontConvertHelper_Cw2Str

func FontConvertHelper_Cw2Str(cw FontCw) string

FontConvertHelper_Cw2Str converts main ASCII characters of a FontCW to a string. (for backward compatibility) Deprecated: Use FontConvertHelperCw2Str(cw FontCw) instead

func FormatFloatTrim

func FormatFloatTrim(floatval float64) (formatted string)

FormatFloatTrim converts a float64 into a string, like Sprintf("%.3f") but with trailing zeroes (and possibly ".") removed

Example
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10.0))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10.01))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10.001))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10.0001))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(10.00001))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(9.99999))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(9.9999))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(9.999))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(9.99))
fmt.Printf("/F1 %s Tf\n", FormatFloatTrim(9.9))
Output:

/F1 10 Tf
/F1 10 Tf
/F1 10.01 Tf
/F1 10.001 Tf
/F1 10 Tf
/F1 10 Tf
/F1 10 Tf
/F1 10 Tf
/F1 9.999 Tf
/F1 9.99 Tf
/F1 9.9 Tf

func GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer fetches a buffer from the pool

func ImgReactagleToWH

func ImgReactagleToWH(imageRect image.Rectangle) (float64, float64)

ImgReactagleToWH Rectangle to W and H

func PointsToUnits

func PointsToUnits(t int, u float64) float64

PointsToUnits converts points to the provided units

func PointsToUnitsVar

func PointsToUnitsVar(t int, u ...*float64)

PointsToUnitsVar converts points to the provided units for all variables supplied

func PutBuffer

func PutBuffer(buf *bytes.Buffer)

PutBuffer returns a buffer to the pool

func ReadShortFromByte

func ReadShortFromByte(data []byte, offset int) (int64, int)

ReadShortFromByte read short from byte array

func ReadUShortFromByte

func ReadUShortFromByte(data []byte, offset int) (uint64, int)

ReadUShortFromByte read ushort from byte array

func StrHelperGetStringWidth

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

StrHelperGetStringWidth get string width

func StrHelperGetStringWidthPrecise

func StrHelperGetStringWidthPrecise(str string, fontSize float64, ifont IFont) float64

StrHelperGetStringWidthPrecise get string width with real number fontSize

func ToByte

func ToByte(chr string) byte

ToByte returns the first byte of a string.

func UnitsToPoints

func UnitsToPoints(t int, u float64) float64

UnitsToPoints converts units of the provided type to points

func UnitsToPointsVar

func UnitsToPointsVar(t int, u ...*float64)

UnitsToPointsVar converts units of the provided type to points for all variables supplied

func WriteBytes

func WriteBytes(w io.Writer, data []byte, offset int, count int) error

WriteBytes writes []byte value to w io.Writer

func WriteTag

func WriteTag(w io.Writer, tag string) error

WriteTag writes string value to w io.Writer

func WriteUInt16

func WriteUInt16(w io.Writer, v uint) error

WriteUInt16 writes a 16-bit unsigned integer value to w io.Writer

func WriteUInt32

func WriteUInt32(w io.Writer, v uint) error

WriteUInt32 writes a 32-bit unsigned integer value to w io.Writer

Types

type BlendModeType

type BlendModeType string
const (
	Hue             BlendModeType = "/Hue"
	Color           BlendModeType = "/Color"
	NormalBlendMode BlendModeType = "/Normal"
	Darken          BlendModeType = "/Darken"
	Screen          BlendModeType = "/Screen"
	Overlay         BlendModeType = "/Overlay"
	Lighten         BlendModeType = "/Lighten"
	Multiply        BlendModeType = "/Multiply"
	Exclusion       BlendModeType = "/Exclusion"
	ColorBurn       BlendModeType = "/ColorBurn"
	HardLight       BlendModeType = "/HardLight"
	SoftLight       BlendModeType = "/SoftLight"
	Difference      BlendModeType = "/Difference"
	Saturation      BlendModeType = "/Saturation"
	Luminosity      BlendModeType = "/Luminosity"
	ColorDodge      BlendModeType = "/ColorDodge"
)

type Box

type Box struct {
	Left, Top, Right, Bottom float64
	// contains filtered or unexported fields
}

func (*Box) UnitsToPoints

func (box *Box) UnitsToPoints(t int) (b *Box)

UnitsToPoints converts the box coordinates to Points. When this is called it is assumed the values of the box are in Units

type BreakMode

type BreakMode int

BreakMode type for text break modes.

const (
	// BreakModeStrict causes the text-line to break immediately in case the current character would not fit into
	// the processed text-line. The separator (if provided) will be attached accordingly as a line suffix
	// to stay within the defined width.
	BreakModeStrict BreakMode = iota

	// BreakModeIndicatorSensitive will try to break the current line based on the last index of a provided
	// BreakIndicator. If no indicator sensitive break can be performed a strict break will be performed,
	// potentially working with the given separator as a suffix.
	BreakModeIndicatorSensitive
)

type BreakOption

type BreakOption struct {
	// Mode defines the mode which should be used
	Mode BreakMode
	// BreakIndicator is taken into account when using indicator sensitive mode to avoid mid-word line breaks
	BreakIndicator rune
	// Separator will act as a suffix for mid-word breaks when using strict mode
	Separator string
}

BreakOption allows to configure the behavior of splitting or breaking larger texts via SplitTextWithOption.

func (BreakOption) HasSeparator

func (bo BreakOption) HasSeparator() bool

type Buff

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

Buff for pdf content

func (*Buff) Bytes

func (b *Buff) Bytes() []byte

Bytes : get bytes

func (*Buff) Len

func (b *Buff) Len() int

Len : len of buffer

func (*Buff) Position

func (b *Buff) Position() int

Position : get current position

func (*Buff) SetPosition

func (b *Buff) SetPosition(pos int)

SetPosition : set current position

func (*Buff) Write

func (b *Buff) Write(p []byte) (int, error)

Write : write []byte to buffer

type CIDFontObj

type CIDFontObj struct {
	PtrToSubsetFontObj *SubsetFontObj
	// contains filtered or unexported fields
}

CIDFontObj is a CID-keyed font. cf. https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5014.CIDFont_Spec.pdf

func (*CIDFontObj) SetIndexObjSubfontDescriptor

func (ci *CIDFontObj) SetIndexObjSubfontDescriptor(index int)

SetIndexObjSubfontDescriptor set indexObjSubfontDescriptor

func (*CIDFontObj) SetPtrToSubsetFontObj

func (ci *CIDFontObj) SetPtrToSubsetFontObj(ptr *SubsetFontObj)

SetPtrToSubsetFontObj set PtrToSubsetFontObj

type CacheContent

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

CacheContent Export cacheContent

func (*CacheContent) Setup

func (c *CacheContent) Setup(rectangle *Rect,
	textColor ICacheColorText,
	grayFill float64,
	fontCountIndex int,
	fontSize float64,
	fontStyle int,
	charSpacing float64,
	setXCount int,
	x, y float64,
	fontSubset *SubsetFontObj,
	pageheight float64,
	contentType int,
	cellOpt CellOption,
	lineWidth float64,
)

Setup setup all information for cacheContent

func (*CacheContent) WriteTextToContent

func (c *CacheContent) WriteTextToContent(text string)

WriteTextToContent write text to content

type CatalogObj

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

CatalogObj : catalog dictionary

func (*CatalogObj) SetIndexObjOutlines

func (c *CatalogObj) SetIndexObjOutlines(index int)

type CellOption

type CellOption struct {
	Align                  int //Allows to align the text. Possible values are: Left,Center,Right,Top,Bottom,Middle
	Border                 int //Indicates if borders must be drawn around the cell. Possible values are: Left, Top, Right, Bottom, ALL
	Float                  int //Indicates where the current position should go after the call. Possible values are: Right, Bottom
	Transparency           *Transparency
	CoefUnderlinePosition  float64
	CoefLineHeight         float64
	CoefUnderlineThickness float64
	BreakOption            *BreakOption
	// contains filtered or unexported fields
}

CellOption cell option

type ColorSpaces

type ColorSpaces string

type Config

type Config struct {
	Unit int // The unit type to use when composing the document.
	//Value that use to convert units to points.
	//If this variable is not 0. This value will be used to calculate the unit conversion instead of the existing const value in the system.
	//And if this variable is not 0. Value ​​in Config.Unit will not be used.
	ConversionForUnit float64
	TrimBox           Box                 // The default trim box for all pages in the document
	PageSize          Rect                // The default page size for all pages in the document
	K                 float64             // Not sure
	Protection        PDFProtectionConfig // Protection settings
}

Config static config

type ContentObj

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

ContentObj content object

func (*ContentObj) AppendStreamCurve

func (c *ContentObj) AppendStreamCurve(x0 float64, y0 float64, x1 float64, y1 float64, x2 float64, y2 float64, x3 float64, y3 float64, style string)

AppendStreamCurve draw curve

  • x0, y0: Start point
  • x1, y1: Control point 1
  • x2, y2: Control point 2
  • x3, y3: End point
  • style: Style of rectangule (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

func (*ContentObj) AppendStreamImage

func (c *ContentObj) AppendStreamImage(index int, opts ImageOptions)

AppendStreamImage append image

func (*ContentObj) AppendStreamImportedTemplate

func (c *ContentObj) AppendStreamImportedTemplate(tplName string, scaleX float64, scaleY float64, tX float64, tY float64)

AppendStreamImportedTemplate append imported template

func (*ContentObj) AppendStreamLine

func (c *ContentObj) AppendStreamLine(x1 float64, y1 float64, x2 float64, y2 float64, lineOpts lineOptions)

AppendStreamLine append line

func (*ContentObj) AppendStreamOval

func (c *ContentObj) AppendStreamOval(x1 float64, y1 float64, x2 float64, y2 float64)

AppendStreamOval append oval

func (*ContentObj) AppendStreamPolygon

func (c *ContentObj) AppendStreamPolygon(points []Point, style string, opts polygonOptions)

AppendStreamPolygon append polygon

func (*ContentObj) AppendStreamRectangle

func (c *ContentObj) AppendStreamRectangle(opts DrawableRectOptions)

func (*ContentObj) AppendStreamSetColorFill

func (c *ContentObj) AppendStreamSetColorFill(r uint8, g uint8, b uint8)

AppendStreamSetColorFill set the color fill

func (*ContentObj) AppendStreamSetColorFillCMYK

func (c *ContentObj) AppendStreamSetColorFillCMYK(cy, m, y, k uint8)

AppendStreamSetColorFillCMYK set the color fill in CMYK color mode

func (*ContentObj) AppendStreamSetColorStroke

func (c *ContentObj) AppendStreamSetColorStroke(r uint8, g uint8, b uint8)

AppendStreamSetColorStroke set the color stroke

func (*ContentObj) AppendStreamSetColorStrokeCMYK

func (c *ContentObj) AppendStreamSetColorStrokeCMYK(cy, m, y, k uint8)

AppendStreamSetColorStrokeCMYK set the color stroke in CMYK color mode

func (*ContentObj) AppendStreamSetCustomLineType

func (c *ContentObj) AppendStreamSetCustomLineType(a []float64, p float64)

AppendStreamSetCustomLineType : set a custom line type

func (*ContentObj) AppendStreamSetGrayFill

func (c *ContentObj) AppendStreamSetGrayFill(w float64)

AppendStreamSetGrayFill set the grayscale fills

func (*ContentObj) AppendStreamSetGrayStroke

func (c *ContentObj) AppendStreamSetGrayStroke(w float64)

AppendStreamSetGrayStroke set the grayscale stroke

func (*ContentObj) AppendStreamSetLineType

func (c *ContentObj) AppendStreamSetLineType(t string)

AppendStreamSetLineType : Set linetype [solid, dashed, dotted]

func (*ContentObj) AppendStreamSetLineWidth

func (c *ContentObj) AppendStreamSetLineWidth(w float64)

AppendStreamSetLineWidth : set line width

func (*ContentObj) AppendStreamSubsetFont

func (c *ContentObj) AppendStreamSubsetFont(rectangle *Rect, text string, cellOpt CellOption) error

AppendStreamSubsetFont add stream of text

func (*ContentObj) AppendStreamText

func (c *ContentObj) AppendStreamText(text string) error

AppendStreamText append text

func (*ContentObj) GetCacheContentImage

func (c *ContentObj) GetCacheContentImage(index int, opts ImageOptions) *cacheContentImage

type CropOptions

type CropOptions struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

type Current

type Current struct {
	X float64
	Y float64

	//font
	IndexOfFontObj int
	CountOfFont    int
	CountOfL       int

	FontSize      float64
	FontStyle     int // Regular|Bold|Italic|Underline
	FontFontCount int
	FontType      int // CURRENT_FONT_TYPE_IFONT or  CURRENT_FONT_TYPE_SUBSET

	CharSpacing float64

	FontISubset *SubsetFontObj // FontType == CURRENT_FONT_TYPE_SUBSET

	//page
	IndexOfPageObj int

	//img
	CountOfImg int
	//cache of image in pdf file
	ImgCaches map[int]ImageCache
	// contains filtered or unexported fields
}

Current current state

type DeviceRGBObj

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

DeviceRGBObj DeviceRGB

type DrawableRectOptions

type DrawableRectOptions struct {
	Rect
	X            float64
	Y            float64
	PaintStyle   PaintStyle
	Transparency *Transparency
	// contains filtered or unexported fields
}

type EmbedFontObj

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

EmbedFontObj is an embedded font object.

func (*EmbedFontObj) SetFont

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

SetFont sets the font of an embedded font object.

type EncodingObj

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

EncodingObj is a font object.

func (*EncodingObj) GetFont

func (e *EncodingObj) GetFont() IFont

GetFont gets the font from an encoding object.

func (*EncodingObj) SetFont

func (e *EncodingObj) SetFont(font IFont)

SetFont sets the font of an encoding object.

type EncryptionObj

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

EncryptionObj encryption object res

type ExtGS

type ExtGS struct {
	Index int
}

ExtGS is ???

type ExtGState

type ExtGState struct {
	Index int

	CA         *float64
	BM         *BlendModeType
	SMaskIndex *int
	// contains filtered or unexported fields
}

TODO: add all fields https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf 8.4.5 page 128

func GetCachedExtGState

func GetCachedExtGState(opts ExtGStateOptions, gp *GoPdf) (ExtGState, error)

type ExtGStateOptions

type ExtGStateOptions struct {
	StrokingCA    *float64
	NonStrokingCa *float64
	BlendMode     *BlendModeType
	SMaskIndex    *int
}

func (ExtGStateOptions) GetId

func (extOpt ExtGStateOptions) GetId() string

type ExtGStatesMap

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

func NewExtGStatesMap

func NewExtGStatesMap() ExtGStatesMap

func (*ExtGStatesMap) Find

func (extm *ExtGStatesMap) Find(extGState ExtGStateOptions) (ExtGState, bool)

func (*ExtGStatesMap) Save

func (tm *ExtGStatesMap) Save(id string, extGState ExtGState) ExtGState

type FontCw

type FontCw map[byte]int

FontCw maps characters to integers.

type FontDescItem

type FontDescItem struct {
	Key string
	Val string
}

FontDescItem is a (key, value) pair.

type FontDescriptorObj

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

FontDescriptorObj is a font descriptor object.

func (*FontDescriptorObj) GetFont

func (f *FontDescriptorObj) GetFont() IFont

GetFont gets font from descriptor.

func (*FontDescriptorObj) SetFont

func (f *FontDescriptorObj) SetFont(font IFont)

SetFont sets the font in descriptor.

func (*FontDescriptorObj) SetFontFileObjRelate

func (f *FontDescriptorObj) SetFontFileObjRelate(relate string)

SetFontFileObjRelate ???

type FontObj

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

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

FontObj font obj

func (*FontObj) SetIndexObjEncoding

func (f *FontObj) SetIndexObjEncoding(index int)

SetIndexObjEncoding sets the encoding.

func (*FontObj) SetIndexObjFontDescriptor

func (f *FontObj) SetIndexObjFontDescriptor(index int)

SetIndexObjFontDescriptor sets the font descriptor.

func (*FontObj) SetIndexObjWidth

func (f *FontObj) SetIndexObjWidth(index int)

SetIndexObjWidth sets the width of a font object.

type FuncKernOverride

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

FuncKernOverride return your custome pair value

type GoPdf

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

GoPdf : A simple library for generating PDF written in Go lang

func (gp *GoPdf) AddExternalLink(url string, x, y, w, h float64)

AddExternalLink adds a new external link.

func (*GoPdf) AddFooter

func (gp *GoPdf) AddFooter(f func())

AddFooter - add a footer function, if present this will be automatically called by AddPage()

func (*GoPdf) AddHeader

func (gp *GoPdf) AddHeader(f func())

AddHeader - add a header function, if present this will be automatically called by AddPage()

func (gp *GoPdf) AddInternalLink(anchor string, x, y, w, h float64)

AddInternalLink adds a new internal link.

func (*GoPdf) AddOutline

func (gp *GoPdf) AddOutline(title string)

func (*GoPdf) AddOutlineWithPosition

func (gp *GoPdf) AddOutlineWithPosition(title string) *OutlineObj

AddOutlineWithPosition add an outline with position

func (*GoPdf) AddPage

func (gp *GoPdf) AddPage()

AddPage : add new page

func (*GoPdf) AddPageWithOption

func (gp *GoPdf) AddPageWithOption(opt PageOption)

AddPageWithOption : add new page with option

func (*GoPdf) AddTTFFont

func (gp *GoPdf) AddTTFFont(family string, ttfpath string) error

AddTTFFont : add font file

func (*GoPdf) AddTTFFontByReader

func (gp *GoPdf) AddTTFFontByReader(family string, rd io.Reader) error

AddTTFFontByReader adds font file by reader.

func (*GoPdf) AddTTFFontByReaderWithOption

func (gp *GoPdf) AddTTFFontByReaderWithOption(family string, rd io.Reader, option TtfOption) error

AddTTFFontByReaderWithOption adds font file by reader with option.

func (*GoPdf) AddTTFFontData

func (gp *GoPdf) AddTTFFontData(family string, fontData []byte) error

AddTTFFontByReader adds font data by reader.

func (*GoPdf) AddTTFFontDataWithOption

func (gp *GoPdf) AddTTFFontDataWithOption(family string, fontData []byte, option TtfOption) error

AddTTFFontDataWithOption adds font data with option.

func (*GoPdf) AddTTFFontWithOption

func (gp *GoPdf) AddTTFFontWithOption(family string, ttfpath string, option TtfOption) error

AddTTFFontWithOption : add font file

func (*GoPdf) Br

func (gp *GoPdf) Br(h float64)

Br : new line

func (*GoPdf) Cell

func (gp *GoPdf) Cell(rectangle *Rect, text string) error

Cell : create cell of text ( use current x,y is upper-left corner of cell) Note that this has no effect on Rect.H pdf (now). Fix later :-)

func (*GoPdf) CellWithOption

func (gp *GoPdf) CellWithOption(rectangle *Rect, text string, opt CellOption) error

CellWithOption create cell of text ( use current x,y is upper-left corner of cell)

func (*GoPdf) ClearTransparency

func (gp *GoPdf) ClearTransparency()

func (*GoPdf) Close

func (gp *GoPdf) Close() error

Close clears the gopdf buffer.

func (*GoPdf) Curve

func (gp *GoPdf) Curve(x0 float64, y0 float64, x1 float64, y1 float64, x2 float64, y2 float64, x3 float64, y3 float64, style string)

Curve Draws a Bézier curve (the Bézier curve is tangent to the line between the control points at either end of the curve) Parameters: - x0, y0: Start point - x1, y1: Control point 1 - x2, y2: Control point 2 - x3, y3: End point - style: Style of rectangule (draw and/or fill: D, F, DF, FD)

func (*GoPdf) FillInPlaceHoldText

func (gp *GoPdf) FillInPlaceHoldText(placeHolderName string, text string, align int) error

[experimental] fill in text that created by function PlaceHolderText align: Left,Right,Center

func (*GoPdf) GetBytesPdf

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

GetBytesPdf : get bytes of pdf file

func (*GoPdf) GetBytesPdfReturnErr

func (gp *GoPdf) GetBytesPdfReturnErr() ([]byte, error)

GetBytesPdfReturnErr : get bytes of pdf file

func (*GoPdf) GetInfo

func (gp *GoPdf) GetInfo() PdfInfo

GetInfo get Document Information Dictionary

func (*GoPdf) GetNextObjectID

func (gp *GoPdf) GetNextObjectID() int

GetNextObjectID gets the next object ID so that gofpdi knows where to start the object IDs.

func (*GoPdf) GetNumberOfPages

func (gp *GoPdf) GetNumberOfPages() int

GetNumberOfPages gets the number of pages from the PDF.

func (*GoPdf) GetX

func (gp *GoPdf) GetX() float64

GetX : get current position X

func (*GoPdf) GetY

func (gp *GoPdf) GetY() float64

GetY : get current position y

func (*GoPdf) Image

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

Image : draw image

func (*GoPdf) ImageByHolder

func (gp *GoPdf) ImageByHolder(img ImageHolder, x float64, y float64, rect *Rect) error

ImageByHolder : draw image by ImageHolder

func (*GoPdf) ImageByHolderWithOptions

func (gp *GoPdf) ImageByHolderWithOptions(img ImageHolder, opts ImageOptions) error

func (*GoPdf) ImageFrom

func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect) error

func (*GoPdf) ImageFromWithOption

func (gp *GoPdf) ImageFromWithOption(img image.Image, opts ImageFromOption) error

func (*GoPdf) ImportObjects

func (gp *GoPdf) ImportObjects(objs map[int]string, startObjID int)

ImportObjects imports objects from gofpdi into current document.

func (*GoPdf) ImportPage

func (gp *GoPdf) ImportPage(sourceFile string, pageno int, box string) int

ImportPage imports a page and return template id. gofpdi code

func (*GoPdf) ImportPageStream

func (gp *GoPdf) ImportPageStream(sourceStream *io.ReadSeeker, pageno int, box string) int

ImportPageStream imports page using a stream. Return template id after importing. gofpdi code

func (*GoPdf) ImportTemplates

func (gp *GoPdf) ImportTemplates(tpls map[string]int)

ImportTemplates names into procset dictionary.

func (*GoPdf) IsCurrFontContainGlyph

func (gp *GoPdf) IsCurrFontContainGlyph(r rune) (bool, error)

IsCurrFontContainGlyph defines is current font contains to a glyph r: any rune

func (*GoPdf) IsFitMultiCell

func (gp *GoPdf) IsFitMultiCell(rectangle *Rect, text string) (bool, float64, error)

IsFitMultiCell : check whether the rectangle's area is big enough for the text

func (*GoPdf) IsFitMultiCellWithNewline

func (gp *GoPdf) IsFitMultiCellWithNewline(rectangle *Rect, text string) (bool, float64, error)

IsFitMultiCellWithNewline : similar to IsFitMultiCell, but process char newline as Br

func (*GoPdf) KernOverride

func (gp *GoPdf) KernOverride(family string, fn FuncKernOverride) error

KernOverride override kern value

func (*GoPdf) Line

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

Line : draw line

Usage:
pdf.SetTransparency(gopdf.Transparency{Alpha: 0.5,BlendModeType: gopdf.ColorBurn})
pdf.SetLineType("dotted")
pdf.SetStrokeColor(255, 0, 0)
pdf.SetLineWidth(2)
pdf.Line(10, 30, 585, 30)
pdf.ClearTransparency()

func (*GoPdf) MarginBottom

func (gp *GoPdf) MarginBottom() float64

MarginBottom returns the bottom margin.

func (*GoPdf) MarginLeft

func (gp *GoPdf) MarginLeft() float64

MarginLeft returns the left margin.

func (*GoPdf) MarginRight

func (gp *GoPdf) MarginRight() float64

MarginRight returns the right margin.

func (*GoPdf) MarginTop

func (gp *GoPdf) MarginTop() float64

MarginTop returns the top margin.

func (*GoPdf) Margins

func (gp *GoPdf) Margins() (float64, float64, float64, float64)

Margins gets the current margins, The margins will be converted back to the documents units. Returned values will be in the following order Left, Top, Right, Bottom

func (*GoPdf) MeasureCellHeightByText

func (gp *GoPdf) MeasureCellHeightByText(text string) (float64, error)

MeasureCellHeightByText : measure Height of cell by text (use current font)

func (*GoPdf) MeasureTextWidth

func (gp *GoPdf) MeasureTextWidth(text string) (float64, error)

MeasureTextWidth : measure Width of text (use current font)

func (*GoPdf) MultiCell

func (gp *GoPdf) MultiCell(rectangle *Rect, text string) error

MultiCell : create of text with line breaks ( use current x,y is upper-left corner of cell)

func (*GoPdf) MultiCellWithOption

func (gp *GoPdf) MultiCellWithOption(rectangle *Rect, text string, opt CellOption) error

MultiCellWithOption create of text with line breaks ( use current x,y is upper-left corner of cell)

func (*GoPdf) Oval

func (gp *GoPdf) Oval(x1 float64, y1 float64, x2 float64, y2 float64)

Oval : draw oval

func (*GoPdf) PlaceHolderText

func (gp *GoPdf) PlaceHolderText(placeHolderName string, placeHolderWidth float64) error

[experimental] PlaceHolderText Create a text placehold for fillin text later with function FillInPlaceHoldText.

func (*GoPdf) PointsToUnits

func (gp *GoPdf) PointsToUnits(u float64) float64

PointsToUnits converts the points to the documents unit type

func (*GoPdf) PointsToUnitsVar

func (gp *GoPdf) PointsToUnitsVar(u ...*float64)

PointsToUnitsVar converts the points to the documents unit type for all variables passed in

func (*GoPdf) Polygon

func (gp *GoPdf) Polygon(points []Point, style string)

Polygon : draw polygon

  • style: Style of polygon (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

Usage:

 pdf.SetStrokeColor(255, 0, 0)
	pdf.SetLineWidth(2)
	pdf.SetFillColor(0, 255, 0)
	pdf.Polygon([]gopdf.Point{{X: 10, Y: 30}, {X: 585, Y: 200}, {X: 585, Y: 250}}, "DF")

func (*GoPdf) Read

func (gp *GoPdf) Read(p []byte) (int, error)

func (*GoPdf) RectFromLowerLeft

func (gp *GoPdf) RectFromLowerLeft(x float64, y float64, wdth float64, hght float64)

RectFromLowerLeft : draw rectangle from lower-left corner (x, y)

func (*GoPdf) RectFromLowerLeftWithOpts

func (gp *GoPdf) RectFromLowerLeftWithOpts(opts DrawableRectOptions) error

func (*GoPdf) RectFromLowerLeftWithStyle

func (gp *GoPdf) RectFromLowerLeftWithStyle(x float64, y float64, wdth float64, hght float64, style string)

RectFromLowerLeftWithStyle : draw rectangle from lower-left corner (x, y)

  • style: Style of rectangule (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

func (*GoPdf) RectFromUpperLeft

func (gp *GoPdf) RectFromUpperLeft(x float64, y float64, wdth float64, hght float64)

RectFromUpperLeft : draw rectangle from upper-left corner (x, y)

func (*GoPdf) RectFromUpperLeftWithOpts

func (gp *GoPdf) RectFromUpperLeftWithOpts(opts DrawableRectOptions) error

func (*GoPdf) RectFromUpperLeftWithStyle

func (gp *GoPdf) RectFromUpperLeftWithStyle(x float64, y float64, wdth float64, hght float64, style string)

RectFromUpperLeftWithStyle : draw rectangle from upper-left corner (x, y)

  • style: Style of rectangule (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

func (*GoPdf) Rectangle

func (gp *GoPdf) Rectangle(x0 float64, y0 float64, x1 float64, y1 float64, style string, radius float64, radiusPointNum int) error

Rectangle : draw rectangle, and add radius input to make a round corner, it helps to calculate the round corner coordinates and use Polygon functions to draw rectangle

  • style: Style of Rectangle (draw and/or fill: D, F, DF, FD) D or empty string: draw. This is the default value. F: fill DF or FD: draw and fill

Usage:

 pdf.SetStrokeColor(255, 0, 0)
	pdf.SetLineWidth(2)
	pdf.SetFillColor(0, 255, 0)
	pdf.Rectangle(196.6, 336.8, 398.3, 379.3, "DF", 3, 10)

func (*GoPdf) Rotate

func (gp *GoPdf) Rotate(angle, x, y float64)

Rotate rotate text or image angle is angle in degrees. x, y is rotation center

func (*GoPdf) RotateReset

func (gp *GoPdf) RotateReset()

RotateReset reset rotate

func (*GoPdf) SetAnchor

func (gp *GoPdf) SetAnchor(name string)

SetAnchor creates a new anchor.

func (*GoPdf) SetCharSpacing

func (gp *GoPdf) SetCharSpacing(charSpacing float64) error

SetCharSpacing : set the character spacing of the currently active font

func (*GoPdf) SetCompressLevel

func (gp *GoPdf) SetCompressLevel(level int)

SetCompressLevel : set compress Level for content streams Possible values for level:

-2 HuffmanOnly, -1 DefaultCompression (which is level 6)
 0 No compression,
 1 fastest compression, but not very good ratio
 9 best compression, but slowest

func (*GoPdf) SetCustomLineType

func (gp *GoPdf) SetCustomLineType(dashArray []float64, dashPhase float64)

SetCustomLineType : set custom line type

Usage:
pdf.SetCustomLineType([]float64{0.8, 0.8}, 0)
pdf.Line(50, 200, 550, 200)

func (*GoPdf) SetFillColor

func (gp *GoPdf) SetFillColor(r uint8, g uint8, b uint8)

SetFillColor set the color for the stroke

func (*GoPdf) SetFillColorCMYK

func (gp *GoPdf) SetFillColorCMYK(c, m, y, k uint8)

SetFillColorCMYK set the color for the fill in CMYK color mode

func (*GoPdf) SetFont

func (gp *GoPdf) SetFont(family string, style string, size interface{}) error

SetFont : set font style support "" or "U" for "B" and "I" should be loaded appropriate fonts with same styles defined size MUST be uint*, int* or float64*

func (*GoPdf) SetFontSize

func (gp *GoPdf) SetFontSize(fontSize float64) error

SetFontSize : set the font size (and only the font size) of the currently active font

func (*GoPdf) SetFontWithStyle

func (gp *GoPdf) SetFontWithStyle(family string, style int, size interface{}) error

SetFontWithStyle : set font style support Regular or Underline for Bold|Italic should be loaded appropriate fonts with same styles defined size MUST be uint*, int* or float64*

func (*GoPdf) SetGrayFill

func (gp *GoPdf) SetGrayFill(grayScale float64)

SetGrayFill set the grayscale for the fill, takes a float64 between 0.0 and 1.0

func (*GoPdf) SetGrayStroke

func (gp *GoPdf) SetGrayStroke(grayScale float64)

SetGrayStroke set the grayscale for the stroke, takes a float64 between 0.0 and 1.0

func (*GoPdf) SetInfo

func (gp *GoPdf) SetInfo(info PdfInfo)

SetInfo set Document Information Dictionary

func (*GoPdf) SetLeftMargin

func (gp *GoPdf) SetLeftMargin(margin float64)

SetLeftMargin sets left margin.

func (*GoPdf) SetLineType

func (gp *GoPdf) SetLineType(linetype string)

SetLineType : set line type ("dashed" ,"dotted")

Usage:
pdf.SetLineType("dashed")
pdf.Line(50, 200, 550, 200)
pdf.SetLineType("dotted")
pdf.Line(50, 400, 550, 400)

func (*GoPdf) SetLineWidth

func (gp *GoPdf) SetLineWidth(width float64)

SetLineWidth : set line width

func (*GoPdf) SetMarginBottom

func (gp *GoPdf) SetMarginBottom(margin float64)

SetMarginBottom set the bottom margin

func (*GoPdf) SetMarginLeft

func (gp *GoPdf) SetMarginLeft(margin float64)

SetMarginLeft sets the left margin

func (*GoPdf) SetMarginRight

func (gp *GoPdf) SetMarginRight(margin float64)

SetMarginRight sets the right margin

func (*GoPdf) SetMarginTop

func (gp *GoPdf) SetMarginTop(margin float64)

SetMarginTop sets the top margin

func (*GoPdf) SetMargins

func (gp *GoPdf) SetMargins(left, top, right, bottom float64)

SetMargins defines the left, top, right and bottom margins. By default, they equal 1 cm. Call this method to change them.

func (*GoPdf) SetNewXY

func (gp *GoPdf) SetNewXY(y float64, x, h float64)

SetNewXY : set current position x and y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element to be inserted is 25px, because 10<25, you need to add another page and set y to 20px. Because of AddPage(), X is set to MarginLeft, so you should specify X if needed, or make sure SetX() is after SetNewY().

func (*GoPdf) SetNewY

func (gp *GoPdf) SetNewY(y float64, h float64)

SetNewY : set current position y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element(such as text) to be inserted is 25px, because 10<25, you need to add another page and set y to 20px. Because of called AddPage(), X is set to MarginLeft, so you should specify X if needed, or make sure SetX() is after SetNewY(), or using SetNewXY(). SetNewYIfNoOffset is more suitable for scenarios where the offset does not change, such as pdf.Image().

func (*GoPdf) SetNewYIfNoOffset

func (gp *GoPdf) SetNewYIfNoOffset(y float64, h float64)

SetNewYIfNoOffset : set current position y, and modified y if add a new page. Example: For example, if the page height is set to 841px, MarginTop is 20px, MarginBottom is 10px, and the height of the element(such as image) to be inserted is 200px, because 10<200, you need to add another page and set y to 20px. Tips: gp.curr.X and gp.curr.Y do not change when pdf.Image() is called.

func (*GoPdf) SetNoCompression

func (gp *GoPdf) SetNoCompression()

SetNoCompression : compressLevel = 0

func (*GoPdf) SetStrokeColor

func (gp *GoPdf) SetStrokeColor(r uint8, g uint8, b uint8)

SetStrokeColor set the color for the stroke

func (*GoPdf) SetStrokeColorCMYK

func (gp *GoPdf) SetStrokeColorCMYK(c, m, y, k uint8)

SetStrokeColorCMYK set the color for the stroke in CMYK color mode

func (*GoPdf) SetTextColor

func (gp *GoPdf) SetTextColor(r uint8, g uint8, b uint8)

SetTextColor : function sets the text color

func (*GoPdf) SetTextColorCMYK

func (gp *GoPdf) SetTextColorCMYK(c, m, y, k uint8)

func (*GoPdf) SetTopMargin

func (gp *GoPdf) SetTopMargin(margin float64)

SetTopMargin sets top margin.

func (*GoPdf) SetTransparency

func (gp *GoPdf) SetTransparency(transparency Transparency) error

SetTransparency sets transparency. alpha: value from 0 (transparent) to 1 (opaque) blendMode: blend mode, one of the following:

Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity

func (*GoPdf) SetX

func (gp *GoPdf) SetX(x float64)

SetX : set current position X

func (*GoPdf) SetXY

func (gp *GoPdf) SetXY(x, y float64)

SetXY : set current position x and y

func (*GoPdf) SetY

func (gp *GoPdf) SetY(y float64)

SetY : set current position y

func (*GoPdf) SplitText

func (gp *GoPdf) SplitText(text string, width float64) ([]string, error)

SplitText splits text into multiple lines based on width performing potential mid-word breaks.

func (*GoPdf) SplitTextWithOption

func (gp *GoPdf) SplitTextWithOption(text string, width float64, opt *BreakOption) ([]string, error)

SplitTextWithOption splits a text into multiple lines based on the current font size of the document. BreakOptions allow to define the behavior of the split (strict or sensitive). For more information see BreakOption.

func (*GoPdf) SplitTextWithWordWrap

func (gp *GoPdf) SplitTextWithWordWrap(text string, width float64) ([]string, error)

SplitTextWithWordWrap behaves the same way SplitText does but performs a word-wrap considering spaces in case a text line split would split a word.

func (*GoPdf) Start

func (gp *GoPdf) Start(config Config)

Start : init gopdf

func (*GoPdf) StartWithImporter

func (gp *GoPdf) StartWithImporter(config Config, importer *gofpdi.Importer)

func (*GoPdf) Text

func (gp *GoPdf) Text(text string) error

Text write text start at current x,y ( current y is the baseline of text )

func (*GoPdf) UnitsToPoints

func (gp *GoPdf) UnitsToPoints(u float64) float64

UnitsToPoints converts the units to the documents unit type

func (*GoPdf) UnitsToPointsVar

func (gp *GoPdf) UnitsToPointsVar(u ...*float64)

UnitsToPointsVar converts the units to the documents unit type for all variables passed in

func (*GoPdf) UseImportedTemplate

func (gp *GoPdf) UseImportedTemplate(tplid int, x float64, y float64, w float64, h float64)

UseImportedTemplate draws an imported PDF page.

func (*GoPdf) Write deprecated

func (gp *GoPdf) Write(w io.Writer) error

Write streams the pdf as it is compiled to an io.Writer

Deprecated: use the WriteTo method instead.

func (*GoPdf) WritePdf

func (gp *GoPdf) WritePdf(pdfPath string) error

WritePdf : write pdf file

func (*GoPdf) WriteTo

func (gp *GoPdf) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements the io.WriterTo interface and can be used to stream the PDF as it is compiled to an io.Writer.

type ICacheColorText

type ICacheColorText interface {
	ICacheContent
	// contains filtered or unexported methods
}

type ICacheContent

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

func NewCacheContentRectangle

func NewCacheContentRectangle(pageHeight float64, rectOpts DrawableRectOptions) ICacheContent

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
}

IFont represents a font interface.

type IObj

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

IObj inteface for all pdf object

type ImageCache

type ImageCache struct {
	Path  string //ID or Path
	Index int
	Rect  *Rect
}

ImageCache is metadata for caching images.

type ImageFromOption

type ImageFromOption struct {
	Format string //jpeg,png
	X      float64
	Y      float64
	Rect   *Rect
}

type ImageHolder

type ImageHolder interface {
	ID() string
	io.Reader
}

ImageHolder hold image data

func ImageHolderByBytes

func ImageHolderByBytes(b []byte) (ImageHolder, error)

ImageHolderByBytes create ImageHolder by []byte

func ImageHolderByPath

func ImageHolderByPath(path string) (ImageHolder, error)

ImageHolderByPath create ImageHolder by image path

func ImageHolderByReader

func ImageHolderByReader(r io.Reader) (ImageHolder, error)

ImageHolderByReader create ImageHolder by io.Reader

type ImageObj

type ImageObj struct {
	//imagepath string
	IsMask       bool
	SplittedMask bool
	// contains filtered or unexported fields
}

ImageObj image object

func (*ImageObj) GetRect

func (i *ImageObj) GetRect() *Rect

GetRect get rect of img

func (*ImageObj) Parse

func (i *ImageObj) Parse() error

Parse parse img

func (*ImageObj) SetImage

func (i *ImageObj) SetImage(r io.Reader) error

SetImage set image

func (*ImageObj) SetImagePath

func (i *ImageObj) SetImagePath(path string) error

SetImagePath set image path

type ImageOptions

type ImageOptions struct {
	DegreeAngle    float64
	VerticalFlip   bool
	HorizontalFlip bool
	X              float64
	Y              float64
	Rect           *Rect
	Mask           *MaskOptions
	Crop           *CropOptions
	Transparency   *Transparency
	// contains filtered or unexported fields
}

type ImportedObj

type ImportedObj struct {
	Data string
}

ImportedObj : imported object

type MapOfCharacterToGlyphIndex

type MapOfCharacterToGlyphIndex struct {
	Keys []rune
	Vals []uint
	// contains filtered or unexported fields
}

MapOfCharacterToGlyphIndex map of CharacterToGlyphIndex

func NewMapOfCharacterToGlyphIndex

func NewMapOfCharacterToGlyphIndex() *MapOfCharacterToGlyphIndex

NewMapOfCharacterToGlyphIndex new CharacterToGlyphIndex

func (*MapOfCharacterToGlyphIndex) AllKeys

func (m *MapOfCharacterToGlyphIndex) AllKeys() []rune

AllKeys get keys

func (*MapOfCharacterToGlyphIndex) AllVals

func (m *MapOfCharacterToGlyphIndex) AllVals() []uint

AllVals get all values

func (*MapOfCharacterToGlyphIndex) Index

func (m *MapOfCharacterToGlyphIndex) Index(k rune) (int, bool)

Index get index by key

func (*MapOfCharacterToGlyphIndex) KeyExists

func (m *MapOfCharacterToGlyphIndex) KeyExists(k rune) bool

KeyExists key is exists?

func (*MapOfCharacterToGlyphIndex) Set

func (m *MapOfCharacterToGlyphIndex) Set(k rune, v uint)

Set set key and value to map

func (*MapOfCharacterToGlyphIndex) Val

Val get value by Key

type Margins

type Margins struct {
	Left, Top, Right, Bottom float64
}

Margins type.

type MaskOptions

type MaskOptions struct {
	ImageOptions
	BBox   *[4]float64
	Holder ImageHolder
}

type OutlineNode

type OutlineNode struct {
	Obj      *OutlineObj
	Children []*OutlineNode
}

OutlineNode is a node of outline

func (OutlineNode) Parse

func (obj OutlineNode) Parse()

Parse parse outline

type OutlineNodes

type OutlineNodes []*OutlineNode

OutlineNodes are all nodes of outline

func (OutlineNodes) Parse

func (objs OutlineNodes) Parse()

Parse parse outline nodes

type OutlineObj

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

OutlineObj include attribute of outline

func (*OutlineObj) GetIndex

func (o *OutlineObj) GetIndex() int

func (*OutlineObj) SetFirst

func (o *OutlineObj) SetFirst(first int)

func (*OutlineObj) SetLast

func (o *OutlineObj) SetLast(last int)

func (*OutlineObj) SetNext

func (o *OutlineObj) SetNext(next int)

func (*OutlineObj) SetParent

func (o *OutlineObj) SetParent(parent int)

func (*OutlineObj) SetPrev

func (o *OutlineObj) SetPrev(prev int)

type OutlinesObj

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

OutlinesObj : outlines dictionary

func (*OutlinesObj) AddOutline

func (o *OutlinesObj) AddOutline(dest int, title string)

func (*OutlinesObj) AddOutlinesWithPosition

func (o *OutlinesObj) AddOutlinesWithPosition(dest int, title string, y float64) *OutlineObj

AddOutlinesWithPosition add outlines with position

func (*OutlinesObj) Count

func (o *OutlinesObj) Count() int

func (*OutlinesObj) SetIndexObjOutlines

func (o *OutlinesObj) SetIndexObjOutlines(index int)

type PDFProtection

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

PDFProtection protection in pdf

func (*PDFProtection) EncryptionObj

func (p *PDFProtection) EncryptionObj() *EncryptionObj

EncryptionObj get Encryption Object

func (*PDFProtection) Objectkey

func (p *PDFProtection) Objectkey(objID int) []byte

Objectkey create object key from ObjID

func (*PDFProtection) SetProtection

func (p *PDFProtection) SetProtection(permissions int, userPass []byte, ownerPass []byte) error

SetProtection set protection information

type PDFProtectionConfig

type PDFProtectionConfig struct {
	UseProtection bool
	Permissions   int
	UserPass      []byte
	OwnerPass     []byte
}

PDFProtectionConfig config of pdf protection

type PageObj

type PageObj struct {
	Contents        string
	ResourcesRelate string

	Links []linkOption
	// contains filtered or unexported fields
}

PageObj pdf page object

type PageOption

type PageOption struct {
	TrimBox  *Box
	PageSize *Rect
}

PageOption option of page

type PagesObj

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

PagesObj pdf pages object

type PaintStyle

type PaintStyle string
const (
	DrawPaintStyle     PaintStyle = "S"
	FillPaintStyle     PaintStyle = "f"
	DrawFillPaintStyle PaintStyle = "B"
)

type PdfDictionaryObj

type PdfDictionaryObj struct {
	PtrToSubsetFontObj *SubsetFontObj
	// contains filtered or unexported fields
}

PdfDictionaryObj pdf dictionary object

func (*PdfDictionaryObj) AddCompositeGlyphs

func (p *PdfDictionaryObj) AddCompositeGlyphs(glyphArray *[]int, glyph int)

AddCompositeGlyphs add composite glyph composite glyph is a Unicode entity that can be defined as a sequence of one or more other characters.

func (*PdfDictionaryObj) GetOffset

func (p *PdfDictionaryObj) GetOffset(glyph int) int

GetOffset get offset from glyf table

func (*PdfDictionaryObj) SetPtrToSubsetFontObj

func (p *PdfDictionaryObj) SetPtrToSubsetFontObj(ptr *SubsetFontObj)

SetPtrToSubsetFontObj set subsetFontObj pointer

type PdfInfo

type PdfInfo struct {
	Title        string    // The document’s title
	Author       string    // The name of the person who created the document
	Subject      string    // The subject of the document
	Creator      string    // If the document was converted to PDF from another format, the name of the application which created the original document
	Producer     string    // If the document was converted to PDF from another format, the name of the application that converted the original document to PDF
	CreationDate time.Time // The date and time the document was created, in human-readable form
}

PdfInfo Document Information Dictionary

type PlaceHolderTextOption

type PlaceHolderTextOption struct {
	//Left 8 , Right 2 ,Center  16
	Align int
}

type Point

type Point struct {
	X float64
	Y float64
}

Point a point in a two-dimensional

type ProcSetObj

type ProcSetObj struct {
	//Font
	Relates             RelateFonts
	RelateXobjs         RelateXobjects
	ExtGStates          []ExtGS
	ImportedTemplateIds map[string]int
	// contains filtered or unexported fields
}

ProcSetObj is a PDF procSet object.

type Rect

type Rect struct {
	W float64
	H float64
	// contains filtered or unexported fields
}

Rect defines a rectangle.

func (*Rect) PointsToUnits

func (rect *Rect) PointsToUnits(t int) (r *Rect)

PointsToUnits converts the rectangles width and height to Units. When this is called it is assumed the values of the rectangle are in Points

func (*Rect) UnitsToPoints

func (rect *Rect) UnitsToPoints(t int) (r *Rect)

UnitsToPoints converts the rectanlges width and height to Points. When this is called it is assumed the values of the rectangle are in Units

type RelateFont

type RelateFont struct {
	Family string
	//etc /F1
	CountOfFont int
	//etc  5 0 R
	IndexOfObj int
	Style      int // Regular|Bold|Italic
}

RelateFont is a metadata index for fonts?

type RelateFonts

type RelateFonts []RelateFont

RelateFonts is a slice of RelateFont.

func (*RelateFonts) IsContainsFamily

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

IsContainsFamily checks if font family exists.

func (*RelateFonts) IsContainsFamilyAndStyle

func (re *RelateFonts) IsContainsFamilyAndStyle(family string, style int) bool

IsContainsFamilyAndStyle checks if font with same name and style already exists .

type RelateXobject

type RelateXobject struct {
	IndexOfObj int
}

RelateXobject is an index for ???

type RelateXobjects

type RelateXobjects []RelateXobject

RelateXobjects is a slice of RelateXobject.

type SMask

type SMask struct {
	Index                         int
	TransparencyXObjectGroupIndex int
	S                             string
	// contains filtered or unexported fields
}

SMask smask

func GetCachedMask

func GetCachedMask(opts SMaskOptions, gp *GoPdf) SMask

type SMaskMap

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

func NewSMaskMap

func NewSMaskMap() SMaskMap

func (*SMaskMap) Find

func (smask *SMaskMap) Find(sMask SMaskOptions) (SMask, bool)

func (*SMaskMap) Save

func (smask *SMaskMap) Save(id string, sMask SMask) SMask

type SMaskOptions

type SMaskOptions struct {
	TransparencyXObjectGroupIndex int
	Subtype                       SMaskSubtypes
}

func (SMaskOptions) GetId

func (smask SMaskOptions) GetId() string

type SMaskSubtypes

type SMaskSubtypes string

type SubfontDescriptorObj

type SubfontDescriptorObj struct {
	PtrToSubsetFontObj *SubsetFontObj
	// contains filtered or unexported fields
}

SubfontDescriptorObj pdf subfont descriptorObj object

func (*SubfontDescriptorObj) SetIndexObjPdfDictionary

func (s *SubfontDescriptorObj) SetIndexObjPdfDictionary(index int)

SetIndexObjPdfDictionary set PdfDictionary pointer

func (*SubfontDescriptorObj) SetPtrToSubsetFontObj

func (s *SubfontDescriptorObj) SetPtrToSubsetFontObj(ptr *SubsetFontObj)

SetPtrToSubsetFontObj set SubsetFont pointer

type SubsetFontObj

type SubsetFontObj struct {
	Family                string
	CharacterToGlyphIndex *MapOfCharacterToGlyphIndex
	CountOfFont           int
	// contains filtered or unexported fields
}

SubsetFontObj pdf subsetFont object

func (*SubsetFontObj) AddChars

func (s *SubsetFontObj) AddChars(txt string) (string, error)

AddChars add char to map CharacterToGlyphIndex

func (*SubsetFontObj) CharCodeToGlyphIndex

func (s *SubsetFontObj) CharCodeToGlyphIndex(r rune) (uint, error)

CharCodeToGlyphIndex gets glyph index from char code.

func (*SubsetFontObj) CharIndex

func (s *SubsetFontObj) CharIndex(r rune) (uint, error)

CharIndex index of char in glyph table

func (*SubsetFontObj) CharWidth

func (s *SubsetFontObj) CharWidth(r rune) (uint, error)

CharWidth with of char

func (*SubsetFontObj) GetAscender

func (s *SubsetFontObj) GetAscender() int

func (*SubsetFontObj) GetAscenderPx

func (s *SubsetFontObj) GetAscenderPx(fontSize float64) float64

func (*SubsetFontObj) GetDescender

func (s *SubsetFontObj) GetDescender() int

func (*SubsetFontObj) GetDescenderPx

func (s *SubsetFontObj) GetDescenderPx(fontSize float64) float64

func (*SubsetFontObj) GetFamily

func (s *SubsetFontObj) GetFamily() string

GetFamily get font family name

func (*SubsetFontObj) GetTTFParser

func (s *SubsetFontObj) GetTTFParser() *core.TTFParser

GetTTFParser gets TTFParser.

func (*SubsetFontObj) GetTtfFontOption

func (s *SubsetFontObj) GetTtfFontOption() TtfOption

GetTtfFontOption get TtfOption must set before SetTTFByPath

func (*SubsetFontObj) GetUnderlinePosition

func (s *SubsetFontObj) GetUnderlinePosition() int

GetUnderlinePosition underline position.

func (*SubsetFontObj) GetUnderlinePositionPx

func (s *SubsetFontObj) GetUnderlinePositionPx(fontSize float64) float64

func (*SubsetFontObj) GetUnderlineThickness

func (s *SubsetFontObj) GetUnderlineThickness() int

GetUnderlineThickness underlineThickness.

func (*SubsetFontObj) GetUnderlineThicknessPx

func (s *SubsetFontObj) GetUnderlineThicknessPx(fontSize float64) float64

func (*SubsetFontObj) GlyphIndexToPdfWidth

func (s *SubsetFontObj) GlyphIndexToPdfWidth(glyphIndex uint) uint

GlyphIndexToPdfWidth gets width from glyphIndex.

func (*SubsetFontObj) KernValueByLeft

func (s *SubsetFontObj) KernValueByLeft(left uint) (bool, *core.KernValue)

KernValueByLeft find kern value from kern table by left

func (*SubsetFontObj) SetFamily

func (s *SubsetFontObj) SetFamily(familyname string)

SetFamily set font family name

func (*SubsetFontObj) SetIndexObjCIDFont

func (s *SubsetFontObj) SetIndexObjCIDFont(index int)

SetIndexObjCIDFont set IndexObjCIDFont

func (*SubsetFontObj) SetIndexObjUnicodeMap

func (s *SubsetFontObj) SetIndexObjUnicodeMap(index int)

SetIndexObjUnicodeMap set IndexObjUnicodeMap

func (*SubsetFontObj) SetTTFByPath

func (s *SubsetFontObj) SetTTFByPath(ttfpath string) error

SetTTFByPath set ttf

func (*SubsetFontObj) SetTTFByReader

func (s *SubsetFontObj) SetTTFByReader(rd io.Reader) error

SetTTFByReader set ttf

func (*SubsetFontObj) SetTTFData

func (s *SubsetFontObj) SetTTFData(data []byte) error

SetTTFData set ttf

func (*SubsetFontObj) SetTtfFontOption

func (s *SubsetFontObj) SetTtfFontOption(option TtfOption)

SetTtfFontOption set TtfOption must set before SetTTFByPath

type Transparency

type Transparency struct {
	Alpha         float64
	BlendModeType BlendModeType
	// contains filtered or unexported fields
}

Transparency defines an object alpha.

func NewTransparency

func NewTransparency(alpha float64, blendModeType string) (Transparency, error)

func (Transparency) GetId

func (t Transparency) GetId() string

type TransparencyMap

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

func NewTransparencyMap

func NewTransparencyMap() TransparencyMap

func (*TransparencyMap) Find

func (tm *TransparencyMap) Find(transparency Transparency) (Transparency, bool)

func (*TransparencyMap) Save

func (tm *TransparencyMap) Save(transparency Transparency) Transparency

type TransparencyXObjectGroup

type TransparencyXObjectGroup struct {
	Index            int
	BBox             [4]float64
	Matrix           [6]float64
	ExtGStateIndexes []int
	XObjects         []cacheContentImage
	// contains filtered or unexported fields
}

type TransparencyXObjectGroupOptions

type TransparencyXObjectGroupOptions struct {
	Protection       *PDFProtection
	ExtGStateIndexes []int
	BBox             [4]float64
	XObjects         []cacheContentImage
}

type TtfOption

type TtfOption struct {
	UseKerning                bool
	Style                     int               //Regular|Bold|Italic
	OnGlyphNotFound           func(r rune)      //Called when a glyph cannot be found, just for debugging
	OnGlyphNotFoundSubstitute func(r rune) rune //Called when a glyph cannot be found, we can return a new rune to replace it.
}

TtfOption font option

type UnicodeMap

type UnicodeMap struct {
	PtrToSubsetFontObj *SubsetFontObj
	// contains filtered or unexported fields
}

UnicodeMap unicode map

func (*UnicodeMap) SetPtrToSubsetFontObj

func (u *UnicodeMap) SetPtrToSubsetFontObj(ptr *SubsetFontObj)

SetPtrToSubsetFontObj set pointer to SubsetFontObj

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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