api

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: May 26, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package api provides support for interacting with pdfcpu.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAttachments

func AddAttachments(fileIn string, files []string, config *pdfcpu.Configuration) error

AddAttachments embeds files into a PDF.

func AddPermissions

func AddPermissions(fileIn string, config *pdfcpu.Configuration) error

AddPermissions sets the user access permissions.

func ChangeOwnerPassword

func ChangeOwnerPassword(fileIn, fileOut string, config *pdfcpu.Configuration, pwOld, pwNew *string) error

ChangeOwnerPassword of fileIn and write result to fileOut.

func ChangeUserPassword

func ChangeUserPassword(fileIn, fileOut string, config *pdfcpu.Configuration, pwOld, pwNew *string) error

ChangeUserPassword of fileIn and write result to fileOut.

func Decrypt

func Decrypt(fileIn, fileOut string, config *pdfcpu.Configuration) error

Decrypt fileIn and write result to fileOut.

func Encrypt

func Encrypt(fileIn, fileOut string, config *pdfcpu.Configuration) error

Encrypt fileIn and write result to fileOut.

func ExtractAttachments

func ExtractAttachments(fileIn, dirOut string, files []string, config *pdfcpu.Configuration) error

ExtractAttachments extracts embedded files from a PDF.

func ExtractContent

func ExtractContent(fileIn, dirOut string, pageSelection []string, config *pdfcpu.Configuration) error

ExtractContent dumps "PDF source" files from fileIn into dirOut for selected pages.

func ExtractFonts

func ExtractFonts(fileIn, dirOut string, pageSelection []string, config *pdfcpu.Configuration) error

ExtractFonts dumps embedded fontfiles from fileIn into dirOut for selected pages.

func ExtractImages

func ExtractImages(fileIn, dirOut string, pageSelection []string, config *pdfcpu.Configuration) error

ExtractImages dumps embedded image resources from fileIn into dirOut for selected pages.

func ExtractPages

func ExtractPages(fileIn, dirOut string, pageSelection []string, config *pdfcpu.Configuration) error

ExtractPages generates single page PDF files from fileIn in dirOut for selected pages.

func ListAttachments

func ListAttachments(fileIn string, config *pdfcpu.Configuration) ([]string, error)

ListAttachments returns a list of embedded file attachments.

func ListPermissions

func ListPermissions(fileIn string, config *pdfcpu.Configuration) ([]string, error)

ListPermissions returns a list of user access permissions.

func Merge

func Merge(filesIn []string, fileOut string, config *pdfcpu.Configuration) 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 *pdfcpu.Configuration) error

Optimize reads in fileIn, does validation, optimization and writes the result to fileOut.

func ParsePageSelection

func ParsePageSelection(s string) ([]string, error)

ParsePageSelection ensures a correct page selection expression.

func Process

func Process(cmd *Command) (out []string, err error)

Process executes a pdfcpu command.

Example (AddAttachments)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

_, err := Process(AddAttachmentsCommand("in.pdf", []string{"a.csv", "b.jpg", "c.pdf"}, config))
if err != nil {
	return
}
Output:

Example (AddPermissions)
config := pdfcpu.NewDefaultConfiguration()
config.UserPW = "upw"
config.OwnerPW = "opw"

config.UserAccessPermissions = pdfcpu.PermissionsAll

_, err := Process(AddPermissionsCommand("in.pdf", config))
if err != nil {
	return
}
Output:

Example (ChangeOwnerPW)
config := pdfcpu.NewDefaultConfiguration()

// supply existing user pw like so
config.UserPW = "upw"

// old and new owner pw
pwOld := "pwOld"
pwNew := "pwNew"

_, err := Process(ChangeOwnerPWCommand("in.pdf", "out.pdf", config, &pwOld, &pwNew))
if err != nil {
	return
}
Output:

Example (ChangeUserPW)
config := pdfcpu.NewDefaultConfiguration()

// supply existing owner pw like so
config.OwnerPW = "opw"

pwOld := "pwOld"
pwNew := "pwNew"

_, err := Process(ChangeUserPWCommand("in.pdf", "out.pdf", config, &pwOld, &pwNew))
if err != nil {
	return
}
Output:

Example (Decrypt)
config := pdfcpu.NewDefaultConfiguration()

config.UserPW = "upw"
config.OwnerPW = "opw"

_, err := Process(DecryptCommand("in.pdf", "out.pdf", config))
if err != nil {
	return
}
Output:

Example (Encrypt)
config := pdfcpu.NewDefaultConfiguration()

config.UserPW = "upw"
config.OwnerPW = "opw"

_, err := Process(EncryptCommand("in.pdf", "out.pdf", config))
if err != nil {
	return
}
Output:

Example (ExtractAttachments)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

// Extract all attachments.
_, err := Process(ExtractAttachmentsCommand("in.pdf", "dirOut", nil, config))
if err != nil {
	return
}

// Extract specific attachments.
_, err = Process(ExtractAttachmentsCommand("in.pdf", "dirOut", []string{"a.csv", "b.pdf"}, config))
if err != nil {
	return
}
Output:

Example (ExtractImages)
// Extract all embedded images for first 5 and last 5 pages but not for page 4.
selectedPages := []string{"-5", "5-", "!4"}

config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

_, err := Process(ExtractImagesCommand("in.pdf", "dirOut", selectedPages, config))
if err != nil {
	return
}
Output:

Example (ExtractPages)
// Extract single-page PDFs for pages 3, 4 and 5.
selectedPages := []string{"3..5"}

config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

_, err := Process(ExtractPagesCommand("in.pdf", "dirOut", selectedPages, config))
if err != nil {
	return
}
Output:

Example (ListAttachments)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = opw"

list, err := Process(ListAttachmentsCommand("in.pdf", config))
if err != nil {
	return
}

// Print attachment list.
for _, l := range list {
	fmt.Println(l)
}
Output:

Example (ListPermissions)
config := pdfcpu.NewDefaultConfiguration()
config.UserPW = "upw"
config.OwnerPW = "opw"

list, err := Process(ListPermissionsCommand("in.pdf", config))
if err != nil {
	return
}

// Print permissions list.
for _, l := range list {
	fmt.Println(l)
}
Output:

Example (Merge)
// Concatenate this sequence of PDF files:
filenamesIn := []string{"in1.pdf", "in2.pdf", "in3.pdf"}

_, err := Process(MergeCommand(filenamesIn, "out.pdf", pdfcpu.NewDefaultConfiguration()))
if err != nil {
	return
}
Output:

Example (Optimize)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

// Generate optional stats.
config.StatsFileName = "stats.csv"

// Configure end of line sequence for writing.
config.Eol = pdfcpu.EolLF

_, err := Process(OptimizeCommand("in.pdf", "out.pdf", config))
if err != nil {
	return
}
Output:

Example (RemoveAttachments)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

// Not to be confused with the ExtractAttachmentsCommand!

// Remove all attachments.
_, err := Process(RemoveAttachmentsCommand("in.pdf", nil, config))
if err != nil {
	return
}

// Remove specific attachments.
_, err = Process(RemoveAttachmentsCommand("in.pdf", []string{"a.csv", "b.jpg"}, config))
if err != nil {
	return
}
Output:

Example (Split)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

// Split into single-page PDFs.

_, err := Process(SplitCommand("in.pdf", "outDir", config))
if err != nil {
	return
}
Output:

Example (Trim)
// Trim to first three pages.
selectedPages := []string{"-3"}

config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

_, err := Process(TrimCommand("in.pdf", "out.pdf", selectedPages, config))
if err != nil {
	return
}
Output:

Example (Validate)
config := pdfcpu.NewDefaultConfiguration()

// Set optional password(s).
//config.UserPW = "upw"
//config.OwnerPW = "opw"

// Set relaxed validation mode.
config.ValidationMode = pdfcpu.ValidationRelaxed

_, err := Process(ValidateCommand("in.pdf", config))
if err != nil {
	return
}
Output:

func Read

func Read(fileIn string, config *pdfcpu.Configuration) (*pdfcpu.PDFContext, error)

Read reads in a PDF file and builds an internal structure holding its cross reference table aka the PDFContext.

func RemoveAttachments

func RemoveAttachments(fileIn string, files []string, config *pdfcpu.Configuration) error

RemoveAttachments deletes embedded files from a PDF.

func Split

func Split(fileIn, dirOut string, config *pdfcpu.Configuration) 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 *pdfcpu.Configuration) error

Trim generates a trimmed version of fileIn containing all pages selected.

func Validate

func Validate(fileIn string, config *pdfcpu.Configuration) error

Validate validates a PDF file against ISO-32000-1:2008.

func Write

func Write(ctx *pdfcpu.PDFContext) error

Write generates a PDF file for a given PDFContext.

Types

type Command

type Command struct {
	Mode          pdfcpu.CommandMode    // VALIDATE  OPTIMIZE  SPLIT  MERGE  EXTRACT  TRIM  LISTATT ADDATT REMATT EXTATT  ENCRYPT  DECRYPT  CHANGEUPW  CHANGEOPW LISTP ADDP
	InFile        *string               //    *         *        *      -       *      *      *       *       *      *       *        *         *          *       *     *
	InFiles       []string              //    -         -        -      *       -      -      -       *       *      *       -        -         -          -       -     -
	InDir         *string               //    -         -        -      -       -      -      -       -       -      -       -        -         -          -       -     -
	OutFile       *string               //    -         *        -      *       -      *      -       -       -      -       *        *         *          *       -     -
	OutDir        *string               //    -         -        *      -       *      -      -       -       -      *       -        -         -          -       -     -
	PageSelection []string              //    -         -        -      -       *      *      -       -       -      -       -        -         -          -       -     -
	Config        *pdfcpu.Configuration //    *         *        *      *       *      *      *       *       *      *       *        *         *          *       *     *
	PWOld         *string               //    -         -        -      -       -      -      -       -       -      -       -        -         *          *       -     -
	PWNew         *string               //    -         -        -      -       -      -      -       -       -      -       -        -         *          *       -     -
}

Command represents an execution context.

func AddAttachmentsCommand

func AddAttachmentsCommand(pdfFileNameIn string, fileNamesIn []string, config *pdfcpu.Configuration) *Command

AddAttachmentsCommand creates a new AddAttachmentsCommand.

func AddPermissionsCommand

func AddPermissionsCommand(pdfFileNameIn string, config *pdfcpu.Configuration) *Command

AddPermissionsCommand creates a new AddPermissionsCommand.

func ChangeOwnerPWCommand

func ChangeOwnerPWCommand(pdfFileNameIn, pdfFileNameOut string, config *pdfcpu.Configuration, pwOld, pwNew *string) *Command

ChangeOwnerPWCommand creates a new ChangeOwnerPWCommand.

func ChangeUserPWCommand

func ChangeUserPWCommand(pdfFileNameIn, pdfFileNameOut string, config *pdfcpu.Configuration, pwOld, pwNew *string) *Command

ChangeUserPWCommand creates a new ChangeUserPWCommand.

func DecryptCommand

func DecryptCommand(pdfFileNameIn, pdfFileNameOut string, config *pdfcpu.Configuration) *Command

DecryptCommand creates a new DecryptCommand.

func EncryptCommand

func EncryptCommand(pdfFileNameIn, pdfFileNameOut string, config *pdfcpu.Configuration) *Command

EncryptCommand creates a new EncryptCommand.

func ExtractAttachmentsCommand

func ExtractAttachmentsCommand(pdfFileNameIn, dirNameOut string, fileNamesIn []string, config *pdfcpu.Configuration) *Command

ExtractAttachmentsCommand creates a new ExtractAttachmentsCommand.

func ExtractContentCommand

func ExtractContentCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *pdfcpu.Configuration) *Command

ExtractContentCommand creates a new ExtractContentCommand.

func ExtractFontsCommand

func ExtractFontsCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *pdfcpu.Configuration) *Command

ExtractFontsCommand creates a new ExtractFontsCommand. (experimental)

func ExtractImagesCommand

func ExtractImagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *pdfcpu.Configuration) *Command

ExtractImagesCommand creates a new ExtractImagesCommand. (experimental)

func ExtractPagesCommand

func ExtractPagesCommand(pdfFileNameIn, dirNameOut string, pageSelection []string, config *pdfcpu.Configuration) *Command

ExtractPagesCommand creates a new ExtractPagesCommand.

func ListAttachmentsCommand

func ListAttachmentsCommand(pdfFileNameIn string, config *pdfcpu.Configuration) *Command

ListAttachmentsCommand create a new ListAttachmentsCommand.

func ListPermissionsCommand

func ListPermissionsCommand(pdfFileNameIn string, config *pdfcpu.Configuration) *Command

ListPermissionsCommand create a new ListPermissionsCommand.

func MergeCommand

func MergeCommand(pdfFileNamesIn []string, pdfFileNameOut string, config *pdfcpu.Configuration) *Command

MergeCommand creates a new MergeCommand.

func OptimizeCommand

func OptimizeCommand(pdfFileNameIn, pdfFileNameOut string, config *pdfcpu.Configuration) *Command

OptimizeCommand creates a new OptimizeCommand.

func RemoveAttachmentsCommand

func RemoveAttachmentsCommand(pdfFileNameIn string, fileNamesIn []string, config *pdfcpu.Configuration) *Command

RemoveAttachmentsCommand creates a new RemoveAttachmentsCommand.

func SplitCommand

func SplitCommand(pdfFileNameIn, dirNameOut string, config *pdfcpu.Configuration) *Command

SplitCommand creates a new SplitCommand.

func TrimCommand

func TrimCommand(pdfFileNameIn, pdfFileNameOut string, pageSelection []string, config *pdfcpu.Configuration) *Command

TrimCommand creates a new TrimCommand.

func ValidateCommand

func ValidateCommand(pdfFileName string, config *pdfcpu.Configuration) *Command

ValidateCommand creates a new ValidateCommand.

Jump to

Keyboard shortcuts

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