Documentation
¶
Overview ¶
Package split 按页面或完整文档体拆分 OFD,保留原包内路径和页面对象 ID。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalid = errors.New("无法拆分 OFD")
ErrInvalid 表示输入、选择、资源或保护关系不满足拆分要求。 具体原因包含在错误文本中;取消和底层读写错误保留原始错误链。
Functions ¶
Types ¶
type DocumentInfo ¶
DocumentInfo 描述输入文档体,Index 从 1 开始。
type Limits ¶
type Limits struct {
MaxInputBytes int64 // 压缩输入,默认 512 MiB。
MaxEntries int // 输入/每份输出的条目数,默认 10000。
MaxEntryBytes int64 // 单条解压大小,默认 64 MiB。
MaxTotalBytes int64 // 输入/每份输出的解压总大小,默认 512 MiB。
MaxParts int // 分卷数,默认 10000。
MaxPages int // 每份输出页数,默认 100000。
MaxOutputBytes int64 // 本会话成功及失败写入的累计压缩字节数,默认 2 GiB。
}
Limits 限制输入、单份结果和批量拆分规模;零值采用有限默认值。
type Options ¶
type Options struct {
Compression creator.CompressionMode
CompressionLevel int
Deterministic bool
KeepAttachments bool // 页面拆分是否复制文档附件;默认移除并清理附件动作。
Signatures creator.SignatureMode // 文档体拆分支持 preserve(默认)和 drop。
DropIntegrity bool // 显式移除完整性清单;否则发现清单时拒绝拆分。
Limits Limits
}
Options 控制拆分输出。页面拆分移除签名、版本、自定义标引和扩展并报告。
type Report ¶
type Report struct {
Document int
Pages []int
SourceID string // 原始文档体 DocID。
DocID string
Dropped []string
DroppedSignatures []string // 被移除的签名 XML 路径。
Signatures []string // 保留的签名 XML 路径;只表示原始字节保留,不表示验签通过。
Bytes int64
}
Report 在写出成功后返回,明确列出发生的内容移除和签名处理。
type Selection ¶
type Selection struct {
Document int
Every int
Groups [][]int // 每组页码从 1 开始;组内不允许重复,组间可重叠。
ByDocument bool
}
Selection 指定拆分分组;Every、Groups、ByDocument 必须且只能设置一个。 页面模式下 Document 从 1 开始,多文档输入必须显式指定。
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 持有已打开输入、XML 缓存和批量引用索引。使用后调用 Close。 方法可并发调用,内部串行处理;调用方持有的 Reader 不会被关闭。
Example ¶
package main
import (
"bytes"
"context"
"fmt"
"github.com/zc310/ofd/pkg/creator"
"github.com/zc310/ofd/pkg/creator/split"
)
func main() {
ctx := context.Background()
input, err := creator.Marshal(creator.Document{ID: "split-example", PageSize: creator.A4, Pages: []creator.Page{{}, {}, {}}})
if err != nil {
panic(err)
}
session, err := split.Open(ctx, input, split.Options{Deterministic: true})
if err != nil {
panic(err)
}
defer session.Close()
parts, err := session.Plan(split.Selection{Every: 2})
if err != nil {
panic(err)
}
for _, part := range parts {
var output bytes.Buffer
report, err := session.Write(ctx, part, &output)
if err != nil {
panic(err)
}
fmt.Println(report.Pages, output.Len() > 0)
}
}
Output: [1 2] true [3] true
Click to show internal directories.
Click to hide internal directories.