cli

package
v0.16.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 27 Imported by: 12

Documentation

Overview

Package cli provides pdfcpu command line processing.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingCommand signals a missing CLI command.
	ErrMissingCommand = errors.New("missing command")

	// ErrInvalidCommandArguments signals an incomplete or structurally invalid CLI command.
	ErrInvalidCommandArguments = errors.New("invalid command arguments")

	// ErrMissingContext signals a missing required Go context.
	ErrMissingContext = contextutil.ErrMissingContext

	// ErrUnsupportedCommandMode signals a command mode unsupported by a dispatcher.
	ErrUnsupportedCommandMode = errors.New("unsupported command mode")
)

Functions

func Dispatch added in v0.13.0

func Dispatch(c context.Context, cmd *Command) (out []string, err error)

Dispatch executes a pdfcpu command with a caller-owned Go context.

func ListAnnotationsFile added in v0.5.0

func ListAnnotationsFile(c context.Context, inFile string, selectedPages []string, conf *model.Configuration) (int, []string, error)

ListAnnotationsFile returns a list of page annotations of inFile and supports cancellation.

func ListAnnotationsJSONFile added in v0.13.0

func ListAnnotationsJSONFile(c context.Context, inFile string, selectedPages []string, conf *model.Configuration) (int, []string, error)

ListAnnotationsJSONFile returns a JSON list of page annotations of inFile and supports cancellation.

func ListAttachmentsCompactFile added in v0.5.0

func ListAttachmentsCompactFile(c context.Context, inFile string, conf *model.Configuration) (ss []string, err error)

ListAttachmentsCompactFile returns a compact list of embedded file attachments of inFile and supports cancellation.

func ListAttachmentsFile added in v0.5.0

func ListAttachmentsFile(c context.Context, inFile string, conf *model.Configuration) (ss []string, err error)

ListAttachmentsFile returns embedded file attachments of inFile with optional descriptions and supports cancellation.

func ListBookmarksFile added in v0.5.0

func ListBookmarksFile(c context.Context, inFile string, conf *model.Configuration) ([]string, error)

ListBookmarksFile returns inFile's bookmarks and supports cancellation.

func ListCertificatesAll added in v0.10.0

func ListCertificatesAll(c context.Context, json bool, _ *model.Configuration) ([]string, error)

ListCertificatesAll returns information about installed certificates and supports cancellation.

func ListFormFieldsFile added in v0.5.0

func ListFormFieldsFile(c context.Context, inFiles []string, conf *model.Configuration) ([]string, error)

ListFormFieldsFile returns form field IDs in inFiles and supports cancellation.

func ListImagesFile added in v0.5.0

func ListImagesFile(c context.Context, inFiles []string, selectedPages []string, conf *model.Configuration) ([]string, error)

ListImagesFile returns a formatted list of embedded images of inFile and supports cancellation.

func ListInfoFile added in v0.5.0

func ListInfoFile(c context.Context, inFile string, selectedPages []string, fonts bool, conf *model.Configuration) ([]string, error)

ListInfoFile returns formatted information about inFile and supports cancellation.

func ListInfoFiles added in v0.5.0

func ListInfoFiles(c context.Context, inFiles []string, selectedPages []string, fonts, json bool, conf *model.Configuration) ([]string, error)

ListInfoFiles returns formatted information about inFiles and supports cancellation.

func ListKeywordsFile added in v0.5.0

func ListKeywordsFile(c context.Context, inFile string, conf *model.Configuration) ([]string, error)

ListKeywordsFile returns the keyword list of inFile and supports cancellation.

func ListPermissionsFile added in v0.5.0

func ListPermissionsFile(c context.Context, inFiles []string, conf *model.Configuration) ([]string, error)

ListPermissionsFile returns user access permissions for inFiles and supports cancellation.

func ListPropertiesFile added in v0.5.0

func ListPropertiesFile(c context.Context, inFile string, conf *model.Configuration) ([]string, error)

ListPropertiesFile returns the property list of inFile and supports cancellation.

Types

type Command

type Command struct {
	Mode              model.CommandMode
	InFile            *string
	InFileCert        *string
	InFilePrivateKey  *string
	InFileJSON        *string
	InFiles           []string
	InDir             *string
	OutFile           *string
	OutFileJSON       *string
	OutDir            *string
	PageSelection     []string
	PWOld             *string
	PWNew             *string
	StringVal         string
	IntVal            int
	BoolVal1          bool
	BoolVal2          bool
	BoolVal3          bool
	IntVals           []int
	StringVals        []string
	StringMap         map[string]string
	Input             io.ReadSeeker
	Inputs            []io.ReadSeeker
	Output            io.Writer
	ErrorOutput       io.Writer
	NoticeOutput      io.Writer
	Box               *model.Box
	Import            *pdfcpu.Import
	NUp               *model.NUp
	Cut               *model.Cut
	PageBoundaries    *model.PageBoundaries
	Resize            *model.Resize
	Zoom              *model.Zoom
	Watermark         *model.Watermark
	ViewerPreferences *model.ViewerPreferences
	PageConf          *pdfcpu.PageConfiguration
	Conf              *model.Configuration
}

Command represents an execution context.

func AddAttachmentsCommand

func AddAttachmentsCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command

AddAttachmentsCommand creates a new command to add attachments.

func AddAttachmentsPortfolioCommand added in v0.3.2

func AddAttachmentsPortfolioCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command

AddAttachmentsPortfolioCommand creates a new command to add attachments to a portfolio.

func AddBoxesCommand added in v0.3.8

func AddBoxesCommand(inFile, outFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command

AddBoxesCommand creates a new command to add page boundaries for selected pages.

func AddKeywordsCommand added in v0.3.2

func AddKeywordsCommand(inFile, outFile string, keywords []string, conf *model.Configuration) *Command

AddKeywordsCommand creates a new command to add keywords.

func AddPropertiesCommand added in v0.3.2

func AddPropertiesCommand(inFile, outFile string, properties map[string]string, conf *model.Configuration) *Command

AddPropertiesCommand creates a new command to add document properties.

func AddWatermarksCommand

func AddWatermarksCommand(inFile, outFile string, pageSelection []string, wm *model.Watermark, conf *model.Configuration) *Command

AddWatermarksCommand creates a new command to add watermarks to a file.

func BookletCommand added in v0.3.9

func BookletCommand(inFiles []string, outFile string, pageSelection []string, nup *model.NUp, conf *model.Configuration) *Command

BookletCommand creates a new command to render PDFs or image files in booklet fashion.

func ChangeOwnerPWCommand

func ChangeOwnerPWCommand(inFile, outFile string, pwOld, pwNew *string, conf *model.Configuration) *Command

ChangeOwnerPWCommand creates a new command to change the owner password.

func ChangeUserPWCommand

func ChangeUserPWCommand(inFile, outFile string, pwOld, pwNew *string, conf *model.Configuration) *Command

ChangeUserPWCommand creates a new command to change the user password.

func CollectCommand added in v0.3.2

func CollectCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command

CollectCommand creates a new command to create a custom PDF page sequence.

func CreateCheatSheetsFontsCommand added in v0.3.7

func CreateCheatSheetsFontsCommand(fontFiles []string, conf *model.Configuration) *Command

CreateCheatSheetsFontsCommand creates single page PDF cheat sheets in current dir.

func CreateCommand added in v0.3.13

func CreateCommand(inFilePDF, inFileJSON, outFilePDF string, conf *model.Configuration) *Command

CreateCommand creates a new command to create a PDF file.

func CropCommand added in v0.3.8

func CropCommand(inFile, outFile string, pageSelection []string, box *model.Box, conf *model.Configuration) *Command

CropCommand creates a new command to apply a cropBox to selected pages.

func CutCommand added in v0.4.1

func CutCommand(inFile, outDir, outFile string, pageSelection []string, cut *model.Cut, conf *model.Configuration) *Command

CutCommand creates a new command to cut and slice pages horizontally or vertically.

func DecryptCommand

func DecryptCommand(inFile, outFile string, conf *model.Configuration) *Command

DecryptCommand creates a new command to decrypt a file.

func DumpCommand added in v0.4.0

func DumpCommand(inFilePDF string, vals []int, conf *model.Configuration) *Command

DumpCommand creates a new command to dump objects on stdout.

func EncryptCommand

func EncryptCommand(inFile, outFile string, conf *model.Configuration) *Command

EncryptCommand creates a new command to encrypt a file.

func ExportBookmarksCommand added in v0.5.0

func ExportBookmarksCommand(inFile, outFileJSON string, conf *model.Configuration) *Command

ExportBookmarksCommand creates a new command to export bookmarks of inFile.

func ExportFormCommand added in v0.4.0

func ExportFormCommand(inFilePDF, outFileJSON string, conf *model.Configuration) *Command

ExportFormCommand creates a new command to export a PDF form.

func ExtractAttachmentsCommand

func ExtractAttachmentsCommand(inFile string, outDir string, fileNames []string, conf *model.Configuration) *Command

ExtractAttachmentsCommand creates a new command to extract attachments.

func ExtractContentCommand

func ExtractContentCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command

ExtractContentCommand creates a new command to extract page content streams.

func ExtractFontsCommand

func ExtractFontsCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command

ExtractFontsCommand creates a new command to extract embedded fonts. (experimental)

func ExtractImagesCommand

func ExtractImagesCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command

ExtractImagesCommand creates a new command to extract embedded images.

func ExtractMetadataCommand

func ExtractMetadataCommand(inFile string, outDir string, conf *model.Configuration) *Command

ExtractMetadataCommand creates a new command to extract metadata streams.

func ExtractPagesCommand

func ExtractPagesCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command

ExtractPagesCommand creates a new command to extract specific pages of a file.

func FillFormCommand added in v0.4.0

func FillFormCommand(inFilePDF, inFileJSON, outFilePDF string, conf *model.Configuration) *Command

FillFormCommand creates a new command to fill a PDF form with data.

func GridCommand added in v0.14.0

func GridCommand(inFiles []string, outFile string, pageSelection []string, nup *model.NUp, conf *model.Configuration) *Command

GridCommand creates a new command to arrange PDF pages or images in a grid.

func ImportBookmarksCommand added in v0.5.0

func ImportBookmarksCommand(inFile, inFileJSON, outFile string, replace bool, conf *model.Configuration) *Command

ImportBookmarksCommand creates a new command to import bookmarks to inFile.

func ImportCertificatesCommand added in v0.10.0

func ImportCertificatesCommand(inFiles []string, conf *model.Configuration) *Command

ImportCertificatesCommand creates a new command to import certificates.

func ImportImagesCommand

func ImportImagesCommand(imageFiles []string, outFile string, imp *pdfcpu.Import, conf *model.Configuration) *Command

ImportImagesCommand creates a new command to import images.

func InfoCommand

func InfoCommand(inFiles []string, pageSelection []string, fonts, json bool, conf *model.Configuration) *Command

InfoCommand creates a new command to output information about inFile.

func InsertPagesCommand

func InsertPagesCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration, mode string, pageConf *pdfcpu.PageConfiguration) *Command

InsertPagesCommand creates a new command to insert a blank page before or after selected pages.

func InspectCertificatesCommand added in v0.11.0

func InspectCertificatesCommand(inFiles []string, conf *model.Configuration) *Command

InspectCertificatesCommand creates a new command to inspect certificates.

func InstallFontsCommand added in v0.3.1

func InstallFontsCommand(fontFiles []string, conf *model.Configuration) *Command

InstallFontsCommand installs true type fonts for embedding.

func ListAnnotationsCommand added in v0.3.12

func ListAnnotationsCommand(inFile string, pageSelection []string, conf *model.Configuration) *Command

ListAnnotationsCommand creates a new command to list annotations for selected pages.

func ListAnnotationsJSONCommand added in v0.13.0

func ListAnnotationsJSONCommand(inFile string, pageSelection []string, conf *model.Configuration) *Command

ListAnnotationsJSONCommand creates a new command to list annotations as JSON.

func ListAttachmentsCommand

func ListAttachmentsCommand(inFile string, conf *model.Configuration) *Command

ListAttachmentsCommand creates a new command to list attachments.

func ListBookmarksCommand added in v0.5.0

func ListBookmarksCommand(inFile string, conf *model.Configuration) *Command

ListBookmarksCommand creates a new command to list bookmarks of inFile.

func ListBoxesCommand added in v0.3.8

func ListBoxesCommand(inFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command

ListBoxesCommand creates a new command to list page boundaries for selected pages.

func ListCertificatesCommand added in v0.10.0

func ListCertificatesCommand(json bool, conf *model.Configuration) *Command

ListCertificatesCommand creates a new command to list installed certificates.

func ListFontsCommand added in v0.3.1

func ListFontsCommand(conf *model.Configuration) *Command

ListFontsCommand returns a list of supported fonts.

func ListFormFieldsCommand added in v0.4.0

func ListFormFieldsCommand(inFiles []string, conf *model.Configuration) *Command

ListFormFieldsCommand creates a new command to list the field ids from a PDF form.

func ListFormFieldsJSONCommand added in v0.13.0

func ListFormFieldsJSONCommand(inFiles []string, conf *model.Configuration) *Command

ListFormFieldsJSONCommand creates a new command to list PDF form fields as export JSON.

func ListImagesCommand added in v0.3.12

func ListImagesCommand(inFiles []string, pageSelection []string, conf *model.Configuration) *Command

ListImagesCommand creates a new command to list images for selected pages.

func ListKeywordsCommand added in v0.3.2

func ListKeywordsCommand(inFile string, conf *model.Configuration) *Command

ListKeywordsCommand creates a new command to list keywords.

func ListPageLayoutCommand added in v0.6.0

func ListPageLayoutCommand(inFile string, conf *model.Configuration) *Command

ListPageLayoutCommand creates a new command to list the document page layout.

func ListPageModeCommand added in v0.6.0

func ListPageModeCommand(inFile string, conf *model.Configuration) *Command

ListPageModeCommand creates a new command to list the document page mode.

func ListPermissionsCommand

func ListPermissionsCommand(inFiles []string, conf *model.Configuration) *Command

ListPermissionsCommand creates a new command to list permissions.

func ListPropertiesCommand added in v0.3.2

func ListPropertiesCommand(inFile string, conf *model.Configuration) *Command

ListPropertiesCommand creates a new command to list document properties.

func ListViewerPreferencesCommand added in v0.6.0

func ListViewerPreferencesCommand(inFile string, all, json bool, conf *model.Configuration) *Command

ListViewerPreferencesCommand creates a new command to list the viewer preferences.

func LockFormCommand added in v0.4.0

func LockFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command

LockFormCommand creates a new command to lock PDF form fields.

func MergeAppendCommand added in v0.3.3

func MergeAppendCommand(inFiles []string, outFile string, dividerPage bool, conf *model.Configuration) *Command

MergeAppendCommand creates a new command to merge files. Any existing outFile PDF content will be preserved and serves as the beginning of the merge result.

func MergeCreateCommand added in v0.3.3

func MergeCreateCommand(inFiles []string, outFile string, dividerPage bool, conf *model.Configuration) *Command

MergeCreateCommand creates a new command to merge files. Outfile will be created. An existing outFile will be overwritten.

func MergeCreateZipCommand added in v0.6.0

func MergeCreateZipCommand(inFiles []string, outFile string, conf *model.Configuration) *Command

MergeCreateZipCommand creates a new command to zip merge 2 files. Outfile will be created. An existing outFile will be overwritten.

func MultiFillFormCommand added in v0.4.0

func MultiFillFormCommand(inFilePDF, inFileData, outDir, outFilePDF string, merge bool, conf *model.Configuration) *Command

MultiFillFormCommand creates a new command to fill multiple PDF forms with JSON or CSV data.

func NDownCommand added in v0.4.1

func NDownCommand(inFile, outDir, outFile string, pageSelection []string, n int, cut *model.Cut, conf *model.Configuration) *Command

NDownCommand creates a new command to cut and slice pages horizontally or vertically.

func NUpCommand

func NUpCommand(inFiles []string, outFile string, pageSelection []string, nUp *model.NUp, conf *model.Configuration) *Command

NUpCommand creates a new command to render PDFs or image files in n-up fashion.

func OptimizeCommand

func OptimizeCommand(inFile, outFile string, conf *model.Configuration) *Command

OptimizeCommand creates a new command to optimize a file.

func PosterCommand added in v0.4.1

func PosterCommand(inFile, outDir, outFile string, pageSelection []string, cut *model.Cut, conf *model.Configuration) *Command

PosterCommand creates a new command to cut and slice pages horizontally or vertically.

func RemoveAnnotationsCommand added in v0.3.12

func RemoveAnnotationsCommand(inFile, outFile string, pageSelection []string, idsAndTypes []string, objNrs []int, conf *model.Configuration) *Command

RemoveAnnotationsCommand creates a new command to remove annotations for selected pages.

func RemoveAttachmentsCommand

func RemoveAttachmentsCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command

RemoveAttachmentsCommand creates a new command to remove attachments.

func RemoveBookmarksCommand added in v0.5.0

func RemoveBookmarksCommand(inFile, outFile string, conf *model.Configuration) *Command

RemoveBookmarksCommand creates a new command to remove all bookmarks from inFile.

func RemoveBoxesCommand added in v0.3.8

func RemoveBoxesCommand(inFile, outFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command

RemoveBoxesCommand creates a new command to remove page boundaries for selected pages.

func RemoveFormFieldsCommand added in v0.4.0

func RemoveFormFieldsCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command

RemoveFormFieldsCommand creates a new command to remove fields from a PDF form.

func RemoveKeywordsCommand added in v0.3.2

func RemoveKeywordsCommand(inFile, outFile string, keywords []string, conf *model.Configuration) *Command

RemoveKeywordsCommand creates a new command to remove keywords.

func RemovePagesCommand

func RemovePagesCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command

RemovePagesCommand creates a new command to remove selected pages.

func RemovePropertiesCommand added in v0.3.2

func RemovePropertiesCommand(inFile, outFile string, propKeys []string, conf *model.Configuration) *Command

RemovePropertiesCommand creates a new command to remove document properties.

func RemoveSignaturesCommand added in v0.12.0

func RemoveSignaturesCommand(inFile, outFile string, conf *model.Configuration) *Command

RemoveSignaturesCommand creates a new command to remove all digital signatures from inFile. Writes to outFile if supplied else overwrites inFile.

func RemoveWatermarksCommand added in v0.2.5

func RemoveWatermarksCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command

RemoveWatermarksCommand creates a new command to remove watermarks from a file.

func ResetFormCommand added in v0.4.0

func ResetFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command

ResetFormCommand creates a new command to reset PDF form fields.

func ResetPageLayoutCommand added in v0.6.0

func ResetPageLayoutCommand(inFile, outFile string, conf *model.Configuration) *Command

ResetPageLayoutCommand creates a new command to reset the document page layout.

func ResetPageModeCommand added in v0.6.0

func ResetPageModeCommand(inFile, outFile string, conf *model.Configuration) *Command

ResetPageModeCommand creates a new command to reset the document page mode.

func ResetViewerPreferencesCommand added in v0.6.0

func ResetViewerPreferencesCommand(inFile, outFile string, conf *model.Configuration) *Command

ResetViewerPreferencesCommand creates a new command to reset the viewer preferences.

func ResizeCommand added in v0.4.0

func ResizeCommand(inFile, outFile string, pageSelection []string, resize *model.Resize, conf *model.Configuration) *Command

ResizeCommand creates a new command to scale selected pages.

func RotateCommand

func RotateCommand(inFile, outFile string, rotation int, pageSelection []string, conf *model.Configuration) *Command

RotateCommand creates a new command to rotate pages.

func SetPageLayoutCommand added in v0.6.0

func SetPageLayoutCommand(inFile, outFile, value string, conf *model.Configuration) *Command

SetPageLayoutCommand creates a new command to set the document page layout.

func SetPageModeCommand added in v0.6.0

func SetPageModeCommand(inFile, outFile, value string, conf *model.Configuration) *Command

SetPageModeCommand creates a new command to set the document page mode.

func SetPermissionsCommand

func SetPermissionsCommand(inFile, outFile string, conf *model.Configuration) *Command

SetPermissionsCommand creates a new command to add permissions.

func SetViewerPreferencesCommand added in v0.6.0

func SetViewerPreferencesCommand(inFilePDF, inFileJSON, outFilePDF, stringJSON string, conf *model.Configuration) *Command

SetViewerPreferencesCommand creates a new command to set the viewer preferences.

func SplitByPageNrCommand added in v0.6.0

func SplitByPageNrCommand(inFile, dirNameOut string, pageNrs []int, conf *model.Configuration) *Command

SplitByPageNrCommand creates a new command to split a file into files along given pages.

func SplitCommand

func SplitCommand(inFile, dirNameOut string, span int, conf *model.Configuration) *Command

SplitCommand creates a new command to split a file according to span or along bookmarks.

func TrimCommand

func TrimCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command

TrimCommand creates a new command to trim the pages of a file.

func UnlockFormCommand added in v0.4.0

func UnlockFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command

UnlockFormCommand creates a new command to unlock PDF form fields.

func UpdateImagesCommand added in v0.9.0

func UpdateImagesCommand(inFile, imageFile, outFile string, objNrOrPageNr int, id string, conf *model.Configuration) *Command

UpdateImagesCommand creates a new command to update images.

func ValidateCommand

func ValidateCommand(inFiles []string, conf *model.Configuration) *Command

ValidateCommand creates a new command to validate a file.

func ValidateSignaturesCommand added in v0.10.0

func ValidateSignaturesCommand(inFile string, all, full bool, conf *model.Configuration) *Command

ValidateSignaturesCommand creates a new command to validate encountered digital signatures in inFile.

func ZoomCommand added in v0.7.0

func ZoomCommand(inFile, outFile string, pageSelection []string, zoom *model.Zoom, conf *model.Configuration) *Command

ZoomCommand creates a new command to zoom in/out of selected pages.

Jump to

Keyboard shortcuts

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