office

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package office 通过 LibreOffice 命令行把 Office 文档(docx/doc/odt/rtf/wps/ pptx/xlsx 等)转换为 PDF。转换依赖目标机器已安装 LibreOffice,本包只做进程 调用与临时文件管理,不引入任何第三方依赖。

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute

DefaultTimeout 是单次转换的默认超时时间。

View Source
const EnvSoffice = "OFD_SOFFICE"

EnvSoffice 是覆盖 LibreOffice 可执行文件路径的环境变量名。

Variables

This section is empty.

Functions

func ConvertToPDF

func ConvertToPDF(ctx context.Context, inputPath string, options Options) ([]byte, error)

ConvertToPDF 把 inputPath 转换为 PDF 并返回 PDF 字节。inputPath 必须是 可读的本地文件;转换在独立临时目录和独立用户配置目录中进行,互不干扰。

func FindSoffice

func FindSoffice(explicit string) (string, error)

FindSoffice 定位 LibreOffice 可执行文件。查找顺序为:显式路径、 OFD_SOFFICE 环境变量、PATH 中的 soffice/libreoffice、平台常见安装路径。 找不到时返回错误,调用方应据此给出可操作的提示。

Types

type Options

type Options struct {
	// Soffice 是可执行文件路径;为空时自动查找。
	Soffice string
	// Timeout 是转换超时;为 0 时使用 DefaultTimeout。
	Timeout time.Duration
	// Filter 覆盖 LibreOffice 的导出过滤器;为空时使用通用 pdf。
	Filter string
	// TempDir 是临时文件根目录;为空时使用系统临时目录。
	TempDir string
}

Options 控制单次转换行为。

Jump to

Keyboard shortcuts

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