convert

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package convert 提供与界面无关的 OFD/PDF 转换及安全输出管理。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Direction

func Direction(path string) (from, to string, err error)

Direction 按文件扩展名确定互转方向,接受大小写混合的扩展名。

func RunBatch

func RunBatch(ctx context.Context, requests []Request, notify func(Event)) error

RunBatch 按顺序转换;单文件失败后继续,取消后标记剩余任务并停止。 notify 在调用协程中同步执行,更新界面时必须切换到 UI 线程。

Types

type Event

type Event struct {
	Index  int
	State  State
	Result Result
	Err    error
}

Event 描述队列中某个任务的状态变化。Index 对应传入请求切片的位置。

type Request

type Request struct {
	Input       string
	OutputDir   string
	RelativeDir string
	Password    string
	LossyImages bool
}

Request 描述一份文件的转换。OutputDir 为空时使用输入目录下的“转换结果”。 RelativeDir 为指定 OutputDir 时保留的相对子目录,必须是本地相对路径。 Password 仅用于打开 PDF,不写入配置或日志。

type Result

type Result struct {
	Output          string
	Diagnostics     []converter.PDFImportDiagnostic
	DiagnosticCount int
}

Result 包含已保存的路径及引擎报告的诊断。尚未保存时 Output 为空; 若发布成功后临时文件清理失败,则保留 Output 并同时返回错误。 Diagnostics 最多保留 100 条,DiagnosticCount 为诊断总数。

func Convert

func Convert(ctx context.Context, req Request) (Result, error)

Convert 转换单个文件。已有文件永不覆盖,重名时追加“ (1)”等序号。 转换和关闭临时文件成功后才保存结果;失败或取消时清理本次创建的文件。

type State

type State string

State 表示任务状态,供界面和批量调用方使用。

const (
	Waiting   State = "等待"
	Running   State = "正在转换"
	Succeeded State = "成功"
	Warned    State = "完成但有提示"
	Failed    State = "失败"
	Canceled  State = "已取消"
)

type StreamProgress

type StreamProgress struct {
	Input                     string
	Succeeded, Warned, Failed int
	DiagnosticCount           int
}

StreamProgress 是可覆盖的进度快照,不持有所有已处理文件的记录。

type StreamSummary

type StreamSummary struct {
	StreamProgress
	LastResult  Result
	OutputDir   string
	Details     []string
	DetailCount int
}

StreamSummary 保存计数和最多 100 条错误/诊断详情。

func RunStream

func RunStream(ctx context.Context, source scan.Source, req Request, progress func(StreamProgress)) (StreamSummary, error)

RunStream 对一份来源边检索边转换,不预先收集目录中的文件列表。 目录重试会重新遍历,已完成的输出仍受重名保护,不提供断点续传。

Jump to

Keyboard shortcuts

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