Documentation
¶
Overview ¶
Package pdf parses PDF file structure: the tokenizer, indirect objects, cross-reference tables and streams, object streams, and the page tree.
It exposes a read-only Document that, once opened, is safe to share across goroutines without locking. Higher layers (filters, the content interpreter, and the rasterizer) build on the objects this package returns.
Index ¶
- Variables
- func Debug(o Object) string
- func IntValue(o Object) (int, bool)
- func Number(o Object) (float64, bool)
- type Array
- type Boolean
- type ContentScanner
- type Dict
- type Document
- func (d *Document) DecodedStream(s *Stream) (data []byte, imageFilter string, err error)
- func (d *Document) GetArray(o Object) Array
- func (d *Document) GetDict(o Object) Dict
- func (d *Document) GetInt(o Object) (int, bool)
- func (d *Document) GetName(o Object) (Name, bool)
- func (d *Document) GetStream(o Object) *Stream
- func (d *Document) Page(i int) (*Page, error)
- func (d *Document) PageCount() int
- func (d *Document) Resolve(o Object) Object
- func (d *Document) Trailer() Dict
- type Integer
- type Name
- type Null
- type Object
- type Page
- type Real
- type Rectangle
- type Reference
- type Stream
- type String
Constants ¶
This section is empty.
Variables ¶
var ErrEncrypted = errors.New("pdf: unsupported encryption")
ErrEncrypted is returned when a document uses an encryption scheme that is not supported: a non-Standard security handler, or a Standard handler with an unsupported /V or /R. Standard-handler documents readable with the empty user password are decrypted transparently; ones needing a real password return ErrEncryptedNeedsPassword instead.
var ErrEncryptedNeedsPassword = errors.New("pdf: document requires a password")
ErrEncryptedNeedsPassword is returned when a document uses the Standard Security Handler but the empty user password does not authenticate, i.e. a non-empty user password would be required to read it. Only empty-password decryption is supported.
Functions ¶
func Debug ¶
Debug returns a human-readable representation of an object. It is not the PDF serialization; it is intended for logging and test output.
Types ¶
type ContentScanner ¶
type ContentScanner struct {
// contains filtered or unexported fields
}
ContentScanner tokenizes a PDF content stream into operands and operators. It reuses the object grammar (numbers, strings, names, arrays, inline dicts) and reports bare keywords as operators. It is used by the content interpreter package; exposing it here avoids duplicating the lexer.
func NewContentScanner ¶
func NewContentScanner(src []byte) *ContentScanner
NewContentScanner returns a scanner over a content stream's bytes.
func (*ContentScanner) Next ¶
func (s *ContentScanner) Next() (obj Object, op string, ok bool, err error)
Next returns the next item. For an operand it returns (obj, "", true, nil). For an operator it returns (nil, opName, true, nil). At EOF it returns (nil, "", false, nil). Operators true/false/null are returned as operand objects (Boolean/Null), matching their meaning in content streams.
func (*ContentScanner) ReadInlineImage ¶
func (s *ContentScanner) ReadInlineImage() (Dict, []byte, error)
ReadInlineImage parses the body of an inline image after the BI operator has been returned by Next. It reads the abbreviated key/value pairs up to the ID keyword, then captures the raw sample bytes up to the EI delimiter, and leaves the scanner positioned to continue with the operators that follow.
The returned dict uses the keys as written (abbreviated, e.g. /W, /H, /CS, /F, /BPC, /IM, /D); the caller is responsible for normalizing them. The data is the verbatim (still-encoded) bytes between the single whitespace after ID and the EI delimiter.
Per the spec the sample data starts after exactly one whitespace byte following ID and ends at EI preceded by whitespace and followed by whitespace or EOF. Because the data is arbitrary binary, EI is only honored at a token boundary (whitespace/delimiter on both sides), so a literal "EI" inside the samples does not end the image prematurely.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a parsed PDF. After Open returns, a Document is read-only and safe for concurrent use by multiple goroutines.
func Parse ¶
Parse parses a PDF from an in-memory byte slice. The slice is retained by the returned Document and must not be modified by the caller.
func (*Document) DecodedStream ¶
DecodedStream returns the fully decoded bytes of a stream, applying its filter chain. Image-only filters (e.g. DCTDecode) are left to the caller; in that case DecodedStream returns the raw bytes together with the remaining image filter name.
func (*Document) GetDict ¶
GetDict resolves o to a Dict (or a Stream's dict), returning nil if it is not a dictionary.
func (*Document) GetStream ¶
GetStream resolves o to a *Stream, returning nil if it is not a stream.
type Name ¶
type Name string
Name is a PDF name object (e.g. /Type). The leading slash is not stored and name escapes (#xx) are already decoded.
type Object ¶
type Object interface {
// contains filtered or unexported methods
}
Object is any PDF object value. Concrete types are: Null, Boolean, Integer, Real, String, Name, Array, Dict, Stream, and Reference.
type Page ¶
type Page struct {
MediaBox Rectangle
CropBox Rectangle
Rotate int // normalized to 0, 90, 180, or 270
Resources Dict // inherited resource dictionary
// contains filtered or unexported fields
}
Page is a single resolved page with its inherited attributes.
func (*Page) ContentBytes ¶
ContentBytes returns the concatenated, fully decoded content streams of the page. Multiple content streams are joined with a single space, per the spec.
type Rectangle ¶
type Rectangle struct {
LLX, LLY, URX, URY float64
}
Rectangle is a PDF rectangle in default user space units (points).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package content interprets a PDF page content stream.
|
Package content interprets a PDF page content stream. |
|
Package extract reconstructs document structure (paragraphs, headings, lists, tables) from a PDF's positioned glyphs and vector graphics, then builds a *cssbox.Box tree the existing conversion writers turn into Markdown/HTML.
|
Package extract reconstructs document structure (paragraphs, headings, lists, tables) from a PDF's positioned glyphs and vector graphics, then builds a *cssbox.Box tree the existing conversion writers turn into Markdown/HTML. |
|
Package filter decodes PDF stream data.
|
Package filter decodes PDF stream data. |
|
jbig2
Package jbig2 一个高性能、零依赖的纯 Go 语言 JBIG2 解码器
|
Package jbig2 一个高性能、零依赖的纯 Go 语言 JBIG2 解码器 |
|
Package function implements the PDF Function objects of ISO 32000-1 §7.10.
|
Package function implements the PDF Function objects of ISO 32000-1 §7.10. |
|
Package pageres resolves the page-/Resources entries the raster and extract backends share: fonts, form XObjects, and their /Matrix and /BBox.
|
Package pageres resolves the page-/Resources entries the raster and extract backends share: fonts, form XObjects, and their /Matrix and /BBox. |