Documentation
¶
Overview ¶
Package importpdf parses pages from existing PDFs into renderer-independent page references for inspection and reconstruction workflows.
Index ¶
- Constants
- Variables
- func GetPageSizes(source any) (map[int]map[string]Size, error)
- func RewriteIndirectRefs(data []byte, refMap map[ObjRef]int) []byte
- type ImportOptions
- type ObjRef
- type Object
- type PageRef
- func (p *PageRef) Content() []byte
- func (p *PageRef) ContentBorrowedWithContext(ctx context.Context) ([]byte, error)
- func (p *PageRef) ContentErr() error
- func (p *PageRef) ContentWithContext(ctx context.Context) ([]byte, error)
- func (p *PageRef) ContentWithError() ([]byte, error)
- func (p *PageRef) EncodedContent() ([]byte, string, bool)
- func (p *PageRef) ForEachObject(fn func(ObjRef, []byte) error) error
- func (p *PageRef) ForEachObjectBorrowed(fn func(ObjRef, []byte) error) error
- func (p *PageRef) ForEachObjectCopy(fn func(ObjRef, []byte) error) error
- func (p *PageRef) HeightPoints() float64
- func (p *PageRef) ObjectCount() int
- func (p *PageRef) ObjectRefs() []ObjRef
- func (p *PageRef) Objects() []Object
- func (p *PageRef) Resources() []byte
- func (p *PageRef) ResourcesBorrowed() []byte
- func (p *PageRef) WidthPoints() float64
- type Size
- type Source
- func Open(source any) (*Source, error)
- func OpenBytes(data []byte) (*Source, error)
- func OpenBytesImmutable(data []byte) (*Source, error)
- func OpenBytesImmutableWithOptions(data []byte, options ImportOptions) (*Source, error)
- func OpenBytesImmutableWithOptionsContext(ctx context.Context, data []byte, options ImportOptions) (*Source, error)
- func OpenBytesWithOptions(data []byte, options ImportOptions) (*Source, error)
- func OpenBytesWithOptionsContext(ctx context.Context, data []byte, options ImportOptions) (*Source, error)
- func OpenFile(path string) (*Source, error)
- func OpenFileWithOptions(path string, options ImportOptions) (*Source, error)
- func OpenFileWithOptionsContext(ctx context.Context, path string, options ImportOptions) (*Source, error)
- func OpenReader(r io.Reader) (*Source, error)
- func OpenReaderAt(r io.ReaderAt, size int64) (*Source, error)
- func OpenReaderAtWithOptions(r io.ReaderAt, size int64, options ImportOptions) (*Source, error)
- func OpenReaderAtWithOptionsContext(ctx context.Context, r io.ReaderAt, size int64, options ImportOptions) (*Source, error)
- func OpenReaderWithOptions(r io.Reader, options ImportOptions) (*Source, error)
- func OpenReaderWithOptionsContext(ctx context.Context, r io.Reader, options ImportOptions) (*Source, error)
- func OpenWithOptions(source any, options ImportOptions) (*Source, error)
- func OpenWithOptionsContext(ctx context.Context, source any, options ImportOptions) (*Source, error)
- func (doc *Source) ForEachObjectBorrowedContext(ctx context.Context, fn func(ObjRef, []byte) error) error
- func (doc *Source) Page(pageNo int, boxName string) (*PageRef, error)
- func (doc *Source) PageContext(ctx context.Context, pageNo int, boxName string) (*PageRef, error)
- func (doc *Source) PageCount() int
- func (doc *Source) PageSizes() map[int]map[string]Size
- type SourceCache
Constants ¶
const ( MaxArrayItems = 10000 MaxDecodedStreamBytes = 32 * 1024 * 1024 MaxDictEntries = 10000 MaxPages = 10000 MaxPageContentBytes = 32 * 1024 * 1024 MaxPageTreeDepth = 512 MaxReferencedObjects = 10000 MaxXrefEntries = 100000 MaxXrefChainLength = 128 MaxValueNesting = 128 )
const MaxSourceBytes = 128 * 1024 * 1024
MaxSourceBytes is the largest PDF source accepted by the built-in importer.
Variables ¶
var ErrSourceTooLarge = errors.New("PDF import source exceeds maximum size")
ErrSourceTooLarge reports that a PDF source exceeded the configured byte limit.
Functions ¶
func GetPageSizes ¶
GetPageSizes returns available page box sizes for a PDF source. Sizes are reported in PDF points.
Types ¶
type ImportOptions ¶
ImportOptions controls parser limits for the built-in PDF importer. Zero fields use package defaults.
type ObjRef ¶
type ObjRef struct {
// contains filtered or unexported fields
}
func (ObjRef) Generation ¶
Generation returns the referenced PDF indirect object generation number.
func (ObjRef) ObjectNumber ¶
ObjectNumber returns the referenced PDF indirect object number.
type PageRef ¶
type PageRef struct {
// contains filtered or unexported fields
}
PageRef is a parsed PDF page ready to be embedded by a renderer.
func (*PageRef) Content ¶
Content returns a copy of the imported page content stream bytes. Use ContentErr to check whether lazy content loading failed.
func (*PageRef) ContentBorrowedWithContext ¶
ContentBorrowedWithContext returns the page content without copying it. The returned slice is owned by PageRef and must not be retained or modified after the PageRef is no longer in use.
func (*PageRef) ContentErr ¶
ContentErr reports the lazy content-loading error, if any.
func (*PageRef) ContentWithContext ¶
ContentWithContext returns a copy of the imported page content stream bytes, checking ctx while lazy content is loaded.
func (*PageRef) ContentWithError ¶
ContentWithError returns a copy of the imported page content stream bytes and reports lazy content-loading errors directly.
func (*PageRef) EncodedContent ¶
EncodedContent returns a preserved encoded content stream and its PDF filter name when the imported page can be embedded without re-encoding.
func (*PageRef) ForEachObject ¶
ForEachObject calls fn for each imported object in sorted reference order. The body slice passed to fn is a copy. Use ForEachObjectBorrowed only for performance-sensitive internal code that can honor borrowed-slice semantics.
func (*PageRef) ForEachObjectBorrowed ¶
ForEachObjectBorrowed calls fn for each imported object in sorted reference order. The body slice is owned by PageRef and must not be retained or modified.
func (*PageRef) ForEachObjectCopy ¶
ForEachObjectCopy calls fn for each imported object in sorted reference order. The body slice passed to fn is a copy.
func (*PageRef) HeightPoints ¶
HeightPoints returns the imported page height in PDF points.
func (*PageRef) ObjectCount ¶
ObjectCount returns the number of indirect objects referenced by the imported page.
func (*PageRef) ObjectRefs ¶
ObjectRefs returns imported object references sorted by object number and generation.
func (*PageRef) Objects ¶
Objects returns the indirect objects referenced by the imported page, sorted by object number and generation.
func (*PageRef) Resources ¶
Resources returns a copy of the imported page resource dictionary bytes.
func (*PageRef) ResourcesBorrowed ¶
ResourcesBorrowed returns the page resource dictionary bytes without copying them. The returned slice is owned by PageRef and must not be retained or modified after the PageRef is no longer in use.
func (*PageRef) WidthPoints ¶
WidthPoints returns the imported page width in PDF points.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
func OpenBytesImmutable ¶
OpenBytesImmutable parses PDF bytes without copying them. The caller must not mutate data while the returned Source is in use.
func OpenBytesImmutableWithOptions ¶
func OpenBytesImmutableWithOptions(data []byte, options ImportOptions) (*Source, error)
OpenBytesImmutableWithOptions parses PDF bytes without copying them using explicit parser limits. The caller must not mutate data while the returned Source is in use.
func OpenBytesImmutableWithOptionsContext ¶
func OpenBytesImmutableWithOptionsContext(ctx context.Context, data []byte, options ImportOptions) (*Source, error)
OpenBytesImmutableWithOptionsContext parses PDF bytes without copying them using explicit parser limits and checks ctx before and after parsing. The caller must not mutate data while the returned Source is in use.
func OpenBytesWithOptions ¶
func OpenBytesWithOptions(data []byte, options ImportOptions) (*Source, error)
OpenBytesWithOptions parses PDF bytes using explicit parser limits.
func OpenBytesWithOptionsContext ¶
func OpenBytesWithOptionsContext(ctx context.Context, data []byte, options ImportOptions) (*Source, error)
OpenBytesWithOptionsContext parses PDF bytes using explicit parser limits and checks ctx before copying and after parsing.
func OpenFileWithOptions ¶
func OpenFileWithOptions(path string, options ImportOptions) (*Source, error)
OpenFileWithOptions parses a PDF file using explicit parser limits.
func OpenFileWithOptionsContext ¶
func OpenFileWithOptionsContext(ctx context.Context, path string, options ImportOptions) (*Source, error)
OpenFileWithOptionsContext parses a PDF file using explicit parser limits and checks ctx before opening and after parsing.
func OpenReader ¶
OpenReader reads and parses a PDF stream.
func OpenReaderAt ¶
OpenReaderAt parses a seekable PDF source without copying the whole file. The caller must keep r readable while the returned Source is used.
func OpenReaderAtWithOptions ¶
OpenReaderAtWithOptions parses a seekable PDF source using explicit parser limits. The caller must keep r readable while the returned Source is used.
func OpenReaderAtWithOptionsContext ¶
func OpenReaderAtWithOptionsContext(ctx context.Context, r io.ReaderAt, size int64, options ImportOptions) (*Source, error)
OpenReaderAtWithOptionsContext parses a seekable PDF source using explicit parser limits and checks ctx before and after parsing. The caller must keep r readable while the returned Source is used.
func OpenReaderWithOptions ¶
func OpenReaderWithOptions(r io.Reader, options ImportOptions) (*Source, error)
OpenReaderWithOptions reads and parses a PDF stream using explicit parser limits.
func OpenReaderWithOptionsContext ¶
func OpenReaderWithOptionsContext(ctx context.Context, r io.Reader, options ImportOptions) (*Source, error)
OpenReaderWithOptionsContext reads and parses a PDF stream using explicit parser limits and checks ctx before and during bounded reads.
func OpenWithOptions ¶
func OpenWithOptions(source any, options ImportOptions) (*Source, error)
OpenWithOptions parses a PDF source using explicit parser limits. source may be a file path string, []byte, io.Reader, or *Source.
func OpenWithOptionsContext ¶
func OpenWithOptionsContext(ctx context.Context, source any, options ImportOptions) (*Source, error)
OpenWithOptionsContext parses a PDF source using explicit parser limits and checks ctx before and after bounded reads/parsing.
func (*Source) ForEachObjectBorrowedContext ¶
func (doc *Source) ForEachObjectBorrowedContext(ctx context.Context, fn func(ObjRef, []byte) error) error
ForEachObjectBorrowedContext calls fn for every in-use classic-xref object in file-offset order. Object bodies are immutable slices owned by Source; callers must not modify or retain them after Source is no longer in use. This low-level traversal is intended for inspection and reconstruction code that must account for objects outside the page-reachable graph.
func (*Source) PageContext ¶
PageContext returns an imported page and checks ctx while resolving page resources, content streams, and referenced objects.
type SourceCache ¶
type SourceCache struct {
// contains filtered or unexported fields
}
SourceCache stores parsed PDF sources for reuse across documents.
func NewSourceCache ¶
func NewSourceCache() *SourceCache
NewSourceCache creates an empty reusable PDF import source cache.
func NewSourceCacheWithMaxBytes ¶
func NewSourceCacheWithMaxBytes(maxBytes int64) *SourceCache
NewSourceCacheWithMaxBytes creates an empty reusable PDF import source cache with a byte budget based on source file sizes. Files larger than maxBytes are parsed successfully but not cached.