Documentation
¶
Index ¶
- func AddWatermark(inputPath, outputPath string, opts WatermarkOptions) error
- func CompressPDF(inputPath, outputPath string, opts CompressOptions) error
- func ConvertPDFFilePageToPNGFile(inputPath, outputPath string, pageNum, outputWidth uint32) error
- func ConvertPDFFileToDocxFile(inputPDFPath, outputDocxPath string) error
- func ConvertPDFFileToDocxFileWithOptions(inputPDFPath, outputDocxPath string, opts ConversionOptions) error
- func DecryptPDF(inputPath, outputPath, password string) error
- func EncryptPDF(inputPath, outputPath string, opts EncryptOptions) error
- func ExpandGlobPatterns(patterns []string) ([]string, error)
- func ExtractPDFPageText(inputPath string, pageNum int) (string, error)
- func ExtractPDFPages(inputPath, outputPath string, pages []int) error
- func ExtractPDFText(inputPath string) (string, error)
- func ExtractPDFTextByPage(inputPath string) ([]string, error)
- func ExtractPDFTextToFile(inputPath, outputPath string) error
- func FilterByExtension(paths []string, ext string) []string
- func GetPDFFileSize(path string) (int64, error)
- func GetPDFPageCount(inputPath string) (int, error)
- func ImagesToPDF(imagePaths []string, outputPath string, opts ImageToPDFOptions) error
- func IsPDFEncrypted(inputPath string) (bool, error)
- func MergePDFFiles(inputPaths []string, outputPath string) error
- func RenderPDFPageToImage(inputPath, outputPath string, pageNum int, opts RenderOptions) error
- func RenderPDFToImages(inputPath, outputDir string, opts RenderOptions) ([]string, error)
- func RotatePDF(inputPath, outputPath string, degrees int) error
- func RotatePDFPages(inputPath, outputPath string, degrees int, pages []int) error
- func SplitPDFFile(inputPath, outputDir string) ([]string, error)
- func WritePDFMetadata(inputPath, outputPath string, meta PDFMetadata) error
- type BatchConversionResult
- func BatchConvertDocxToPDF(inputPaths []string, outputDir string, ...) BatchConversionResult
- func BatchConvertDocxToPDFWithProgress(inputPaths []string, outputDir string, ...) BatchConversionResult
- func BatchConvertPDFToDocx(inputPaths []string, outputDir string, opts ConversionOptions) BatchConversionResult
- func BatchConvertPDFToDocxWithProgress(inputPaths []string, outputDir string, opts ConversionOptions, ...) BatchConversionResult
- type BatchResult
- type CompressOptions
- type CompressionResult
- type ConversionOptions
- type EncryptOptions
- type ExtractedImage
- type ImageToPDFOptions
- type PDFMetadata
- type PDFPermissions
- type ProgressCallback
- type RenderOptions
- type WatermarkOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWatermark ¶ added in v0.4.0
func AddWatermark(inputPath, outputPath string, opts WatermarkOptions) error
AddWatermark adds a text or image watermark to a PDF.
func CompressPDF ¶ added in v0.4.0
func CompressPDF(inputPath, outputPath string, opts CompressOptions) error
CompressPDF optimizes a PDF file to reduce its size.
func ConvertPDFFilePageToPNGFile ¶
ConvertPDFFilePageToPNGFile reads a PDF file and converts the specified page to a PNG file at the specified output path.
func ConvertPDFFileToDocxFile ¶ added in v0.4.0
ConvertPDFFileToDocxFile extracts text from a PDF file and creates a DOCX file. This is a basic text extraction - formatting and images are not preserved.
func ConvertPDFFileToDocxFileWithOptions ¶ added in v0.4.0
func ConvertPDFFileToDocxFileWithOptions(inputPDFPath, outputDocxPath string, opts ConversionOptions) error
ConvertPDFFileToDocxFileWithOptions extracts content from a PDF file and creates a DOCX file with enhanced formatting based on the provided options.
func DecryptPDF ¶ added in v0.4.0
DecryptPDF removes password protection from a PDF file.
func EncryptPDF ¶ added in v0.4.0
func EncryptPDF(inputPath, outputPath string, opts EncryptOptions) error
EncryptPDF encrypts a PDF file with password protection.
func ExpandGlobPatterns ¶ added in v0.4.0
ExpandGlobPatterns expands glob patterns to a list of file paths. Non-glob patterns are returned as-is if they exist.
func ExtractPDFPageText ¶ added in v0.4.0
ExtractPDFPageText extracts text from a specific page of a PDF file. Page numbers are 1-indexed.
func ExtractPDFPages ¶ added in v0.4.0
ExtractPDFPages extracts specific pages from a PDF file. Pages are 1-indexed. Returns the output file path.
func ExtractPDFText ¶ added in v0.4.0
ExtractPDFText extracts all text from a PDF file.
func ExtractPDFTextByPage ¶ added in v0.4.0
ExtractPDFTextByPage extracts text from each page of a PDF file. Returns a slice of strings, one per page.
func ExtractPDFTextToFile ¶ added in v0.4.0
ExtractPDFTextToFile extracts text from a PDF and writes it to a file.
func FilterByExtension ¶ added in v0.4.0
FilterByExtension filters a list of paths to include only those with the specified extension.
func GetPDFFileSize ¶ added in v0.4.0
GetPDFFileSize returns the file size in bytes.
func GetPDFPageCount ¶ added in v0.4.0
GetPDFPageCount returns the number of pages in a PDF file.
func ImagesToPDF ¶ added in v0.4.0
func ImagesToPDF(imagePaths []string, outputPath string, opts ImageToPDFOptions) error
ImagesToPDF combines multiple images into a single PDF file.
func IsPDFEncrypted ¶ added in v0.4.0
IsPDFEncrypted checks if a PDF file is password protected.
func MergePDFFiles ¶ added in v0.4.0
MergePDFFiles merges multiple PDF files into a single output file. The files are merged in the order provided.
func RenderPDFPageToImage ¶ added in v0.4.0
func RenderPDFPageToImage(inputPath, outputPath string, pageNum int, opts RenderOptions) error
RenderPDFPageToImage renders a single page from a PDF as an image.
func RenderPDFToImages ¶ added in v0.4.0
func RenderPDFToImages(inputPath, outputDir string, opts RenderOptions) ([]string, error)
RenderPDFToImages renders all pages of a PDF as images. Returns the list of created image file paths.
func RotatePDF ¶ added in v0.4.0
RotatePDF rotates all pages in a PDF by the specified degrees. Valid rotation values are 0, 90, 180, or 270.
func RotatePDFPages ¶ added in v0.4.0
RotatePDFPages rotates specific pages in a PDF by the specified degrees. If pages is empty or nil, all pages are rotated. Valid rotation values are 0, 90, 180, or 270.
func SplitPDFFile ¶ added in v0.4.0
SplitPDFFile splits a PDF file into individual pages or page ranges. If outputDir is empty, files are created in the same directory as the input. Returns the list of created file paths.
func WritePDFMetadata ¶ added in v0.4.0
func WritePDFMetadata(inputPath, outputPath string, meta PDFMetadata) error
WritePDFMetadata updates metadata in a PDF file. Only non-empty fields in meta will be updated.
Types ¶
type BatchConversionResult ¶ added in v0.4.0
type BatchConversionResult struct {
Results []BatchResult `json:"results"`
TotalFiles int `json:"total_files"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
}
BatchConversionResult represents the result of a batch conversion operation.
func BatchConvertDocxToPDF ¶ added in v0.4.0
func BatchConvertDocxToPDF(inputPaths []string, outputDir string, converter func(input, output string) error) BatchConversionResult
BatchConvertDocxToPDF converts multiple DOCX files to PDF format. If outputDir is empty, output files are created in the same directory as the inputs.
func BatchConvertDocxToPDFWithProgress ¶ added in v0.4.0
func BatchConvertDocxToPDFWithProgress(inputPaths []string, outputDir string, converter func(input, output string) error, progress ProgressCallback) BatchConversionResult
BatchConvertDocxToPDFWithProgress converts multiple DOCX files to PDF format with progress reporting. If outputDir is empty, output files are created in the same directory as the inputs.
func BatchConvertPDFToDocx ¶ added in v0.4.0
func BatchConvertPDFToDocx(inputPaths []string, outputDir string, opts ConversionOptions) BatchConversionResult
BatchConvertPDFToDocx converts multiple PDF files to DOCX format. If outputDir is empty, output files are created in the same directory as the inputs.
func BatchConvertPDFToDocxWithProgress ¶ added in v0.4.0
func BatchConvertPDFToDocxWithProgress(inputPaths []string, outputDir string, opts ConversionOptions, progress ProgressCallback) BatchConversionResult
BatchConvertPDFToDocxWithProgress converts multiple PDF files to DOCX format with progress reporting. If outputDir is empty, output files are created in the same directory as the inputs.
type BatchResult ¶ added in v0.4.0
type BatchResult struct {
InputPath string `json:"input_path"`
OutputPath string `json:"output_path"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
BatchResult represents the result of a single file conversion in a batch operation.
type CompressOptions ¶ added in v0.4.0
type CompressOptions struct {
ImageQuality int `json:"image_quality"` // 1-100, lower = more compression
Linearize bool `json:"linearize"` // Optimize for web viewing
}
CompressOptions configures PDF compression.
func DefaultCompressOptions ¶ added in v0.4.0
func DefaultCompressOptions() CompressOptions
DefaultCompressOptions returns default compression options.
type CompressionResult ¶ added in v0.4.0
type CompressionResult struct {
OriginalSize int64 `json:"original_size"`
CompressedSize int64 `json:"compressed_size"`
Ratio float64 `json:"ratio"` // compressed/original
SavingsPercent float64 `json:"savings_percent"`
}
CompressionResult contains information about PDF compression.
func CompressPDFWithStats ¶ added in v0.4.0
func CompressPDFWithStats(inputPath, outputPath string, opts CompressOptions) (CompressionResult, error)
CompressPDFWithStats compresses a PDF and returns compression statistics.
type ConversionOptions ¶ added in v0.4.0
type ConversionOptions struct {
ExtractTables bool // Extract and convert tables
ExtractImages bool // Extract and embed images
DetectLayout bool // Detect headings and text structure
}
ConversionOptions controls the PDF to DOCX conversion behavior.
func DefaultConversionOptions ¶ added in v0.4.0
func DefaultConversionOptions() ConversionOptions
DefaultConversionOptions returns the default conversion options with all features enabled.
type EncryptOptions ¶ added in v0.4.0
type EncryptOptions struct {
UserPassword string `json:"user_password"` // Password to open PDF
OwnerPassword string `json:"owner_password"` // Password for full access
Permissions PDFPermissions `json:"permissions"`
}
EncryptOptions configures PDF encryption.
type ExtractedImage ¶ added in v0.4.0
type ExtractedImage struct {
PageNumber int `json:"page_number"`
Index int `json:"index"`
Format string `json:"format"`
Width int `json:"width"`
Height int `json:"height"`
FilePath string `json:"file_path,omitempty"`
}
ExtractedImage represents an extracted image from a PDF.
func ExtractPDFImages ¶ added in v0.4.0
func ExtractPDFImages(inputPath, outputDir string) ([]ExtractedImage, error)
ExtractPDFImages extracts all images from a PDF file to an output directory. Returns information about each extracted image.
type ImageToPDFOptions ¶ added in v0.4.0
type ImageToPDFOptions struct {
PageSize string `json:"page_size"` // letter, a4, or fit
Margin float64 `json:"margin"` // margin in points
}
ImageToPDFOptions configures image to PDF conversion.
func DefaultImageToPDFOptions ¶ added in v0.4.0
func DefaultImageToPDFOptions() ImageToPDFOptions
DefaultImageToPDFOptions returns default options for image to PDF conversion.
type PDFMetadata ¶ added in v0.4.0
type PDFMetadata struct {
Title string `json:"title,omitempty"`
Author string `json:"author,omitempty"`
Subject string `json:"subject,omitempty"`
Keywords string `json:"keywords,omitempty"`
Creator string `json:"creator,omitempty"`
Producer string `json:"producer,omitempty"`
CreationDate time.Time `json:"creation_date,omitempty"`
ModDate time.Time `json:"mod_date,omitempty"`
PageCount int `json:"page_count"`
Version string `json:"version,omitempty"`
Encrypted bool `json:"encrypted"`
FileSize int64 `json:"file_size"`
}
PDFMetadata contains PDF document properties.
func ReadPDFMetadata ¶ added in v0.4.0
func ReadPDFMetadata(inputPath string) (PDFMetadata, error)
ReadPDFMetadata reads metadata from a PDF file.
type PDFPermissions ¶ added in v0.4.0
type PDFPermissions struct {
Printing bool `json:"printing"`
ModifyContents bool `json:"modify_contents"`
CopyContents bool `json:"copy_contents"`
ModifyAnnots bool `json:"modify_annots"`
}
PDFPermissions configures PDF access permissions.
func DefaultPDFPermissions ¶ added in v0.4.0
func DefaultPDFPermissions() PDFPermissions
DefaultPDFPermissions returns default permissions (all allowed).
type ProgressCallback ¶ added in v0.4.0
ProgressCallback is called during batch operations to report progress. current is the 1-based index of the current file, total is the total count. inputPath is the file being processed.
type RenderOptions ¶ added in v0.4.0
type RenderOptions struct {
Format string `json:"format"` // png, jpeg
DPI float64 `json:"dpi"` // default 150
Quality int `json:"quality"` // jpeg quality 1-100
}
RenderOptions configures PDF page rendering.
func DefaultRenderOptions ¶ added in v0.4.0
func DefaultRenderOptions() RenderOptions
DefaultRenderOptions returns default rendering options.
type WatermarkOptions ¶ added in v0.4.0
type WatermarkOptions struct {
Text string `json:"text"` // Text watermark content
ImagePath string `json:"image_path"` // Path to image watermark (alternative to text)
FontSize float64 `json:"font_size"` // Font size for text watermark
FontName string `json:"font_name"` // Font name (e.g., Helvetica)
Color string `json:"color"` // Hex color (e.g., "#FF0000")
Opacity float64 `json:"opacity"` // 0.0-1.0
Rotation float64 `json:"rotation"` // Degrees
Position string `json:"position"` // center, top-left, top-right, bottom-left, bottom-right
Pages []int `json:"pages"` // Empty = all pages
}
WatermarkOptions configures watermark appearance.
func DefaultWatermarkOptions ¶ added in v0.4.0
func DefaultWatermarkOptions() WatermarkOptions
DefaultWatermarkOptions returns default watermark options.