Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package config 定义 PDF 导入配置,不依赖 PDF 解析器,供 converter 与导入器共享。

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitExceeded = errors.New("PDF 导入超过资源上限")
View Source
var ErrUnsupported = errors.New("PDF 导入遇到无法保留的内容")

Functions

This section is empty.

Types

type Diagnostic

type Diagnostic struct {
	Code       string
	Page       int
	Object     int
	Generation int
	Resource   string
	Message    string
}

Diagnostic 描述无法完整保留的内容。Page 从 1 开始,未知的对象编号为 0。

type ImageMode

type ImageMode string

ImageMode 控制 PDF 图片写入 OFD 时的编码策略。

const (
	// ImageModeCompatible 保持默认的颜色兼容输出路径。
	ImageModeCompatible ImageMode = "compatible"
	// ImageModeCompact 对符合条件的不透明 CMYK JPEG 使用有损 RGB JPEG。
	ImageModeCompact ImageMode = "compact"
	// DefaultJPEGQuality 是 compact 模式未指定时的 JPEG 质量。
	DefaultJPEGQuality = 90
)

type JPXBackend

type JPXBackend string

JPXBackend selects the JPEG 2000 decoder used for PDF JPX images. The OpenJPEG backend requires a Linux build with CGO_ENABLED=1 and -tags openjpeg.

const (
	JPXBackendGo       JPXBackend = "go"
	JPXBackendOpenJPEG JPXBackend = "openjpeg"
)

type LimitError

type LimitError struct {
	Resource string
	Limit    int64
	Actual   int64
}

LimitError 可通过 errors.Is(err, ErrLimitExceeded) 和 errors.As 识别。 Actual 是已观察到的用量;解码提前终止时为超过上限的最小已知用量。

func (*LimitError) Error

func (e *LimitError) Error() string

func (*LimitError) Unwrap

func (e *LimitError) Unwrap() error

type Limits

type Limits struct {
	// 字节预算分别作用于原始输入、单编码流、单解码流和累计解码流。
	MaxInputBytes int64
	MaxPages      int64
	// MaxObjects 同时约束对象数及 xref 可引用的编号范围。
	MaxObjects            int64
	MaxStreamBytes        int64
	MaxDecodedStreamBytes int64
	MaxTotalDecodedBytes  int64
	MaxImagePixels        int64
	MaxTotalImagePixels   int64
	MaxFontBytes          int64
	MaxOutputObjects      int64
	// MaxOperations 计入内容解析、映射展开、遮罩/网格与 Type 4 函数解析和求值。
	MaxOperations int64
	MaxDepth      int64
}

Limits 控制一次转换的资源预算。零值字段使用默认值,负值无效。

func DefaultLimits

func DefaultLimits() Limits

type Options

type Options struct {
	Limits       Limits
	Strict       bool
	ImageMode    ImageMode
	JPEGQuality  int
	JPXBackend   JPXBackend
	OnDiagnostic func(Diagnostic)
}

Options 控制 PDF 导入。Strict 遇到已报告的内容缺失或近似转换即失败, 不代表完整实现 PDF 规范。OnDiagnostic 在转换协程中同步执行;取消该转换的 context 会原样返回 ctx.Err()。并行转换共用回调时,调用方应自行同步共享数据。

func (Options) Normalize

func (o Options) Normalize() (Options, error)

Normalize 校验限制并补齐零值字段,返回独立的配置值。

Jump to

Keyboard shortcuts

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