Documentation ¶
Overview ¶
Package pdfcpu is a simple PDF processing library written in Go. It provides both an API and a command line tool. Supported are all versions up to PDF 1.7 (ISO-32000).
The available commands are:
validate validate PDF against PDF 32000-1:2008 (PDF 1.7) optimize optimize PDF by getting rid of redundant page resources split split multi-page PDF into several single-page PDFs merge concatenate 2 or more PDFs extract extract images, fonts, content, pages out of a PDF trim create trimmed version of a PDF version print pdfcpu version
Index ¶
- Constants
- func ExtractContent(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
- func ExtractFonts(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
- func ExtractImages(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
- func ExtractPages(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
- func Merge(filesIn []string, fileOut string, config *types.Configuration) (err error)
- func Optimize(fileIn, fileOut string, config *types.Configuration) (err error)
- func ParsePageSelection(s string) (ps []string, err error)
- func Process(cmd *Command) (err error)
- func Read(fileIn string, config *types.Configuration) (ctx *types.PDFContext, err error)
- func Split(fileIn, dirOut string, config *types.Configuration) (err error)
- func Trim(fileIn, fileOut string, pageSelection *[]string, config *types.Configuration) (err error)
- func Validate(fileIn string, config *types.Configuration) (err error)
- func Verbose(verbose bool)
- func Write(ctx *types.PDFContext) (err error)
- type Command
- func ExtractContentCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, ...) Command
- func ExtractFontsCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, ...) Command
- func ExtractImagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, ...) Command
- func ExtractPagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, ...) Command
- func MergeCommand(pdfFileNamesIn []string, pdfFileNameOut string, config *types.Configuration) Command
- func OptimizeCommand(pdfFileNameIn, pdfFileNameOut string, config *types.Configuration) Command
- func SplitCommand(pdfFileNameIn, dirNameOut string, config *types.Configuration) Command
- func TrimCommand(pdfFileNameIn, pdfFileNameOut string, pageSelection []string, ...) Command
- func ValidateCommand(pdfFileName string, config *types.Configuration) Command
Examples ¶
Constants ¶
const ( VALIDATE commandMode = iota OPTIMIZE SPLIT MERGE EXTRACTIMAGES EXTRACTFONTS EXTRACTPAGES EXTRACTCONTENT TRIM )
The available commands for the CLI.
Variables ¶
This section is empty.
Functions ¶
func ExtractContent ¶
func ExtractContent(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
ExtractContent dumps "PDF source" files from fileIn into dirOut for selected pages.
func ExtractFonts ¶
func ExtractFonts(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
ExtractFonts dumps embedded fontfiles from fileIn into dirOut for selected pages.
func ExtractImages ¶
func ExtractImages(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
ExtractImages dumps embedded image resources from fileIn into dirOut for selected pages.
func ExtractPages ¶
func ExtractPages(fileIn, dirOut string, pageSelection *[]string, config *types.Configuration) (err error)
ExtractPages generates single page PDF files from fileIn in dirOut for selected pages.
func Merge ¶
func Merge(filesIn []string, fileOut string, config *types.Configuration) (err error)
Merge some PDF files together and write the result to fileOut. This corresponds to concatenating these files in the order specified by filesIn. The first entry of filesIn serves as the destination xRefTable where all the remaining files gets merged into.
func Optimize ¶
func Optimize(fileIn, fileOut string, config *types.Configuration) (err error)
Optimize reads in fileIn, does validation, optimization and writes the result to fileOut.
func ParsePageSelection ¶
ParsePageSelection ensures a correct page selection expression.
func Process ¶
Process executes a pdfcpu command.
Example (ExtractImages) ¶
// Extract all embedded images for first 5 and last 5 pages but not for page 4. selectedPages := []string{"-5", "5-", "!4"} cmd := ExtractImagesCommand("in.pdf", "dirOut", selectedPages, types.NewDefaultConfiguration()) err := Process(&cmd) if err != nil { return }
Output:
Example (ExtractPages) ¶
// Extract single-page PDFs for pages 3, 4 and 5. selectedPages := []string{"3..5"} cmd := ExtractPagesCommand("in.pdf", "dirOut", selectedPages, types.NewDefaultConfiguration()) err := Process(&cmd) if err != nil { return }
Output:
Example (Merge) ¶
// Concatenate this sequence of PDF files: filenamesIn := []string{"in1.pdf", "in2.pdf", "in3.pdf"} cmd := MergeCommand(filenamesIn, "out.pdf", types.NewDefaultConfiguration()) err := Process(&cmd) if err != nil { return }
Output:
Example (Optimize) ¶
config := types.NewDefaultConfiguration() // Generate optional stats. config.StatsFileName = "stats.csv" // Configure end of line sequence for writing. config.Eol = types.EolLF cmd := OptimizeCommand("in.pdf", "out.pdf", config) err := Process(&cmd) if err != nil { return }
Output:
Example (Split) ¶
// Split into single-page PDFs. cmd := SplitCommand("in.pdf", "outDir", types.NewDefaultConfiguration()) err := Process(&cmd) if err != nil { return }
Output:
Example (Trim) ¶
// Trim to first three pages. selectedPages := []string{"-3"} cmd := TrimCommand("in.pdf", "out.pdf", selectedPages, types.NewDefaultConfiguration()) err := Process(&cmd) if err != nil { return }
Output:
Example (Validate) ¶
config := types.NewDefaultConfiguration() // Set relaxed validation mode. config.SetValidationRelaxed() cmd := ValidateCommand("in.pdf", config) err := Process(&cmd) if err != nil { return }
Output:
func Read ¶
func Read(fileIn string, config *types.Configuration) (ctx *types.PDFContext, err error)
Read reads in a PDF file and builds an internal structure holding its cross reference table aka the PDFContext.
func Split ¶
func Split(fileIn, dirOut string, config *types.Configuration) (err error)
Split generates a sequence of single page PDF files in dirOut creating one file for every page of inFile.
func Trim ¶
func Trim(fileIn, fileOut string, pageSelection *[]string, config *types.Configuration) (err error)
Trim generates a trimmed version of fileIn containing all pages selected.
func Validate ¶
func Validate(fileIn string, config *types.Configuration) (err error)
Validate validates a PDF file against ISO-32000-1:2008.
func Write ¶
func Write(ctx *types.PDFContext) (err error)
Write generates a PDF file for a given PDFContext.
Types ¶
type Command ¶
type Command struct { Mode commandMode // VALIDATE OPTIMIZE SPLIT MERGE EXTRACT TRIM InFile *string // * * * - * * InFiles *[]string // - - - * - - OutFile *string // - * - * - * OutDir *string // - - * - * - PageSelection *[]string // - - - - * * Config *types.Configuration // * * * * * * }
Command represents an execution context.
func ExtractContentCommand ¶
func ExtractContentCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *types.Configuration) Command
ExtractContentCommand creates a new ExtractContentCommand.
func ExtractFontsCommand ¶
func ExtractFontsCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *types.Configuration) Command
ExtractFontsCommand creates a new ExtractFontsCommand. (experimental)
func ExtractImagesCommand ¶
func ExtractImagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *types.Configuration) Command
ExtractImagesCommand creates a new ExtractImagesCommand. (experimental)
func ExtractPagesCommand ¶
func ExtractPagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *types.Configuration) Command
ExtractPagesCommand creates a new ExtractPagesCommand.
func MergeCommand ¶
func MergeCommand(pdfFileNamesIn []string, pdfFileNameOut string, config *types.Configuration) Command
MergeCommand creates a new MergeCommand.
func OptimizeCommand ¶
func OptimizeCommand(pdfFileNameIn, pdfFileNameOut string, config *types.Configuration) Command
OptimizeCommand creates a new OptimizeCommand.
func SplitCommand ¶
func SplitCommand(pdfFileNameIn, dirNameOut string, config *types.Configuration) Command
SplitCommand creates a new SplitCommand.
func TrimCommand ¶
func TrimCommand(pdfFileNameIn, pdfFileNameOut string, pageSelection []string, config *types.Configuration) Command
TrimCommand creates a new TrimCommand.
func ValidateCommand ¶
func ValidateCommand(pdfFileName string, config *types.Configuration) Command
ValidateCommand creates a new ValidateCommand.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package extract provides methods for extracting fonts, images, pages and page content.
|
Package extract provides methods for extracting fonts, images, pages and page content. |
Package filter contains implementations for PDF filters.
|
Package filter contains implementations for PDF filters. |
Package merge provides code for merging two PDFContexts.
|
Package merge provides code for merging two PDFContexts. |
Package optimize contains code for optimizing the resources of a PDF file.
|
Package optimize contains code for optimizing the resources of a PDF file. |
Package read provides methods for parsing PDF files into memory.
|
Package read provides methods for parsing PDF files into memory. |
Package types provides the PDFContext, representing an ecosystem for PDF processing.
|
Package types provides the PDFContext, representing an ecosystem for PDF processing. |
Package validate contains validation code for ISO 32000-1:2008.
|
Package validate contains validation code for ISO 32000-1:2008. |
Package write contains code that writes PDF data from memory to a file.
|
Package write contains code that writes PDF data from memory to a file. |