<commit_before>package pdft

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"strconv"
	"strings"

	gopdf "github.com/signintech/pdft/minigopdf"
)

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

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

//Left left
const Left = gopdf.Left //001000
//Top top
const Top = gopdf.Top //000100
//Right right
const Right = gopdf.Right //000010
//Bottom bottom
const Bottom = gopdf.Bottom //000001
//Center center
const Center = gopdf.Center //010000
//Middle middle
const Middle = gopdf.Middle //100000

//PDFt inject text to pdf
type PDFt struct {
	pdf           PDFData
	fontDatas     map[string]*PDFFontData
	pdfImgs       []*PDFImageData
	curr          current
	contenters    []Contenter
	pdfProtection *gopdf.PDFProtection
}

type current struct {
	fontName  string
	fontStyle int
	fontSize  int
	lineWidth float64
}

func pageHeight() float64 {
	return 841.89
}

func (i *PDFt) protection() *gopdf.PDFProtection {
	return i.pdfProtection
}

//ShowCellBorder  show cell of border
func (i *PDFt) ShowCellBorder(isShow bool) {
	var clw ContentLineStyle
	if isShow {
		clw.width = 0.1
		clw.lineType = "dotted"
		i.curr.lineWidth = 0.1
	} else {
		clw.width = 0.0
		clw.lineType = ""
		i.curr.lineWidth = 0.0
	}
	i.contenters = append(i.contenters, &clw)
}

//Open open pdf file
func (i *PDFt) Open(filepath string) error {
	//init
	i.fontDatas = make(map[string]*PDFFontData)
	i.curr.lineWidth = 1.0
	//open
	f, err := os.Open(filepath)
	if err != nil {
		return err
	}
	defer f.Close()

	err = PDFParse(f, &i.pdf)
	if err != nil {<commit_msg>Adds OpenFrom variant to complement SaveTo<commit_after>package pdft

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"strconv"
	"strings"

	gopdf "github.com/signintech/pdft/minigopdf"
)

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

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

//Left left
const Left = gopdf.Left //001000
//Top top
const Top = gopdf.Top //000100
//Right right
const Right = gopdf.Right //000010
//Bottom bottom
const Bottom = gopdf.Bottom //000001
//Center center
const Center = gopdf.Center //010000
//Middle middle
const Middle = gopdf.Middle //100000

//PDFt inject text to pdf
type PDFt struct {
	pdf           PDFData
	fontDatas     map[string]*PDFFontData
	pdfImgs       []*PDFImageData
	curr          current
	contenters    []Contenter
	pdfProtection *gopdf.PDFProtection
}

type current struct {
	fontName  string
	fontStyle int
	fontSize  int
	lineWidth float64
}

func pageHeight() float64 {
	return 841.89
}

func (i *PDFt) protection() *gopdf.PDFProtection {
	return i.pdfProtection
}

//ShowCellBorder  show cell of border
func (i *PDFt) ShowCellBorder(isShow bool) {
	var clw ContentLineStyle
	if isShow {
		clw.width = 0.1
		clw.lineType = "dotted"
		i.curr.lineWidth = 0.1
	} else {
		clw.width = 0.0
		clw.lineType = ""
		i.curr.lineWidth = 0.0
	}
	i.contenters = append(i.contenters, &clw)
}

//Open open pdf file
func (i *PDFt) Open(filepath string) error {
	f, err := os.Open(filepath)
	if err != nil {
		return err
	}
	defer f.Close()

	return i.OpenFrom(f)
}

//OpenFrom open pdf from io.Reader
func (i *PDFt) OpenFrom(r io.Reader) error {
	//init
	i.fontDatas = make(map[string]*PDFFontData)
	i.curr.lineWidth = 1.0
	//open
	err := PDFParse(r, &i.pdf)
	if err != nil {
{'fraction_non_alphanumeric': 0.11626591230551626, 'fraction_numerical': 0.031117397454031116, 'mean_word_length': 3.376237623762376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2151613', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1325, 'n_words': 370}