Documentation
¶
Overview ¶
Package reader parses existing PDF files and exposes basic page metadata, content streams, text extraction, and merge conveniences.
Index ¶
- Variables
- type Box
- type Modifier
- func ExtractPages(r *PdfReader, pageIndexes ...int) (*Modifier, error)
- func Merge(readers ...*PdfReader) (*Modifier, error)
- func MergeFiles(paths ...string) (*Modifier, error)
- func RedactPattern(r *PdfReader, pattern *regexp.Regexp, opts *RedactOptions) (*Modifier, error)
- func RedactText(r *PdfReader, targets []string, opts *RedactOptions) (*Modifier, error)
- func (m *Modifier) AddBlankPage(width, height float64) error
- func (m *Modifier) Bytes() []byte
- func (m *Modifier) CropPage(index int, rect [4]float64) error
- func (m *Modifier) PageCount() int
- func (m *Modifier) RemovePage(index int) error
- func (m *Modifier) ReorderPages(order []int) error
- func (m *Modifier) RotatePage(index, degrees int) error
- func (m *Modifier) SaveTo(path string) error
- type PageInfo
- type PdfReader
- type ReadOptions
- type RedactOptions
- type Strictness
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCannotReadFile is returned when Load cannot read a PDF from disk. ErrCannotReadFile = errors.New("reader: cannot read file") // ErrEncryptedUnsupported is returned for encrypted PDFs. ErrEncryptedUnsupported = errors.New("reader: encrypted PDFs are not supported") // ErrPageOutOfRange is returned when Page receives an invalid index. ErrPageOutOfRange = errors.New("reader: page index out of range") // ErrUnsupportedPDF is returned for PDF constructs not supported by this foundation parser. ErrUnsupportedPDF = errors.New("reader: unsupported PDF") )
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct {
X1, Y1, X2, Y2 float64
}
Box represents a PDF rectangle in points: lower-left (X1,Y1) to upper-right (X2,Y2).
type Modifier ¶
type Modifier struct {
// contains filtered or unexported fields
}
Modifier contains the bytes produced by reader operations such as Merge.
func ExtractPages ¶
ExtractPages copies selected zero-based pages from r into a new PDF. The output order follows pageIndexes.
func MergeFiles ¶
MergeFiles loads and merges PDF files from disk.
func RedactPattern ¶
RedactPattern permanently removes regex matches from uncompressed page content streams by replacing matched bytes with spaces.
func RedactText ¶
func RedactText(r *PdfReader, targets []string, opts *RedactOptions) (*Modifier, error)
RedactText permanently removes literal text targets from uncompressed page content streams by replacing matched bytes with spaces.
func (*Modifier) AddBlankPage ¶
AddBlankPage appends one blank page with dimensions in PDF points.
func (*Modifier) RemovePage ¶
RemovePage removes the zero-based page at index.
func (*Modifier) ReorderPages ¶
ReorderPages rearranges pages according to order, a zero-based permutation.
func (*Modifier) RotatePage ¶
RotatePage sets the zero-based page rotation. Degrees must be a multiple of 90.
type PageInfo ¶
type PageInfo struct {
Number int
Width float64
Height float64
Rotate int
MediaBox Box
CropBox Box
BleedBox Box
TrimBox Box
ArtBox Box
// contains filtered or unexported fields
}
PageInfo holds parsed metadata for one PDF page.
func (*PageInfo) ContentStream ¶
ContentStream returns the decoded page content stream bytes.
func (*PageInfo) ExtractText ¶
ExtractText extracts simple text operators from decoded page content streams.
func (*PageInfo) VisibleBox ¶
VisibleBox returns the effective visible page box.
type PdfReader ¶
type PdfReader struct {
// contains filtered or unexported fields
}
PdfReader holds parsed state for an existing PDF.
func ParseWithOptions ¶
func ParseWithOptions(data []byte, opts ReadOptions) (*PdfReader, error)
ParseWithOptions reads and parses a PDF byte slice with custom options.
type ReadOptions ¶
type ReadOptions struct {
Strictness Strictness
}
ReadOptions configures PDF parsing.
type RedactOptions ¶
type RedactOptions struct {
FillColor [3]float64
OverlayText string
OverlayFontSize float64
OverlayColor [3]float64
// StripMetadata empties the document information dictionary and any
// uncompressed XMP /Metadata stream. A compressed metadata stream is
// reported as an error instead of being left in the output.
StripMetadata bool
}
RedactOptions configures redaction behavior.
This foundation performs byte-preserving text removal and, with StripMetadata, byte-preserving metadata removal. The visual overlay fields are kept for API compatibility with richer redaction flows and are not drawn.
type Strictness ¶
type Strictness int
Strictness controls how the reader handles unsupported stream filters.
const ( // StrictnessTolerant preserves undecodable streams as raw data where possible. StrictnessTolerant Strictness = iota // StrictnessStrict fails when a page content stream uses an unsupported filter. StrictnessStrict )