Documentation
Overview ¶
Package api lets you integrate pdfcpu's operations into your Go backend.
There are two api layers supporting all pdfcpu operations:
1) The file based layer (used by pdfcpu's cli) 2) The io.ReadSeeker/io.Writer based layer for backend integration.
For any pdfcpu command there are two functions.
The file based function always calls the io.ReadSeeker/io.Writer based function:
func CommandFile(inFile, outFile string, conf *pdf.Configuration) error func Command(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
eg. for optimization:
func OptimizeFile(inFile, outFile string, conf *pdf.Configuration) error func Optimize(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
Index ¶
- func AddAttachments(rs io.ReadSeeker, w io.Writer, files []string, conf *pdf.Configuration) error
- func AddAttachmentsFile(inFile, outFile string, files []string, conf *pdf.Configuration) (err error)
- func AddWatermarks(rs io.ReadSeeker, w io.Writer, selectedPages []string, wm *pdf.Watermark, ...) error
- func AddWatermarksFile(inFile, outFile string, selectedPages []string, wm *pdf.Watermark, ...) (err error)
- func ChangeOwnerPasswordFile(inFile, outFile string, pwOld, pwNew string, conf *pdf.Configuration) error
- func ChangeUserPasswordFile(inFile, outFile string, pwOld, pwNew string, conf *pdf.Configuration) error
- func CreatePDFFile(xRefTable *pdf.XRefTable, outFile string, conf *pdf.Configuration) error
- func DecryptFile(inFile, outFile string, conf *pdf.Configuration) error
- func EncryptFile(inFile, outFile string, conf *pdf.Configuration) error
- func ExtractAttachments(rs io.ReadSeeker, outDir string, fileNames []string, conf *pdf.Configuration) error
- func ExtractAttachmentsFile(inFile, outDir string, fileNames []string, conf *pdf.Configuration) error
- func ExtractContent(rs io.ReadSeeker, outDir string, selectedPages []string, ...) error
- func ExtractContentFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
- func ExtractFonts(rs io.ReadSeeker, outDir string, selectedPages []string, ...) error
- func ExtractFontsFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
- func ExtractImages(rs io.ReadSeeker, outDir string, selectedPages []string, ...) error
- func ExtractImagesFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
- func ExtractMetadata(rs io.ReadSeeker, outDir string, selectedPages []string, ...) error
- func ExtractMetadataFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
- func ExtractPages(rs io.ReadSeeker, outDir string, selectedPages []string, ...) error
- func ExtractPagesFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
- func FontNames() []string
- func HasWatermarks(rs io.ReadSeeker, conf *pdf.Configuration) (bool, error)
- func HasWatermarksFile(inFile string, conf *pdf.Configuration) (bool, error)
- func ImportImages(rs io.ReadSeeker, w io.Writer, imgs []io.Reader, imp *pdf.Import, ...) error
- func ImportImagesFile(imgFiles []string, outFile string, imp *pdf.Import, conf *pdf.Configuration) (err error)
- func Info(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
- func InfoFile(inFile string, conf *pdf.Configuration) ([]string, error)
- func InsertPages(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
- func InsertPagesFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
- func ListAttachments(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
- func ListAttachmentsFile(inFile string, conf *pdf.Configuration) ([]string, error)
- func ListPermissions(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
- func ListPermissionsFile(inFile string, conf *pdf.Configuration) ([]string, error)
- func Merge(rsc []io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
- func MergeFile(inFiles []string, outFile string, conf *pdf.Configuration) error
- func NUp(rs io.ReadSeeker, w io.Writer, imgFiles, selectedPages []string, nup *pdf.NUp, ...) error
- func NUpFile(inFiles []string, outFile string, selectedPages []string, nup *pdf.NUp, ...) (err error)
- func Optimize(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
- func OptimizeContext(ctx *pdf.Context) error
- func OptimizeFile(inFile, outFile string, conf *pdf.Configuration) (err error)
- func PageCount(rs io.ReadSeeker, conf *pdf.Configuration) (int, error)
- func PageCountFile(inFile string) (int, error)
- func PageDims(rs io.ReadSeeker, conf *pdf.Configuration) ([]pdf.Dim, error)
- func PageDimsFile(inFile string) ([]pdf.Dim, error)
- func ParsePageSelection(s string) ([]string, error)
- func ReadContext(rs io.ReadSeeker, conf *pdf.Configuration) (*pdf.Context, error)
- func ReadContextFile(inFile string) (*pdf.Context, error)
- func RemoveAttachments(rs io.ReadSeeker, w io.Writer, fileNames []string, conf *pdf.Configuration) error
- func RemoveAttachmentsFile(inFile, outFile string, files []string, conf *pdf.Configuration) (err error)
- func RemovePages(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
- func RemovePagesFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
- func RemoveWatermarks(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
- func RemoveWatermarksFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
- func Rotate(rs io.ReadSeeker, w io.Writer, rotation int, selectedPages []string, ...) error
- func RotateFile(inFile, outFile string, rotation int, selectedPages []string, ...) (err error)
- func SetPermissions(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
- func SetPermissionsFile(inFile, outFile string, conf *pdf.Configuration) (err error)
- func Split(rs io.ReadSeeker, outDir, fileName string, span int, conf *pdf.Configuration) error
- func SplitFile(inFile, outDir string, span int, conf *pdf.Configuration) error
- func Trim(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
- func TrimFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
- func Validate(rs io.ReadSeeker, conf *pdf.Configuration) error
- func ValidateContext(ctx *pdf.Context) error
- func ValidateFile(inFile string, conf *pdf.Configuration) error
- func WatermarkContext(ctx *pdf.Context, selectedPages pdf.IntSet, wm *pdf.Watermark) error
- func WriteContext(ctx *pdf.Context, w io.Writer) error
- func WriteContextFile(ctx *pdf.Context, outFile string) error
- type ReadSeekerCloser
Examples ¶
- AddAttachmentsFile
- AddWatermarksFile
- ChangeOwnerPasswordFile
- ChangeUserPasswordFile
- DecryptFile
- EncryptFile
- ExtractAttachmentsFile
- ExtractContentFile
- ExtractFontsFile
- ExtractImagesFile
- ExtractMetadataFile
- ExtractPagesFile
- ImportImagesFile
- InsertPagesFile
- ListAttachmentsFile
- ListPermissionsFile
- MergeFile
- NUpFile
- OptimizeFile
- RemoveAttachmentsFile
- RemovePagesFile
- RemoveWatermarksFile
- RotateFile
- SetPermissionsFile
- SplitFile
- TrimFile
- ValidateFile
Constants ¶
Variables ¶
Functions ¶
func AddAttachments ¶
func AddAttachments(rs io.ReadSeeker, w io.Writer, files []string, conf *pdf.Configuration) error
AddAttachments embeds files into a PDF context read from rs and writes the result to w.
func AddAttachmentsFile ¶
func AddAttachmentsFile(inFile, outFile string, files []string, conf *pdf.Configuration) (err error)
AddAttachmentsFile embeds files into a PDF context read from inFile and writes the result to outFile.
Example ¶
Output:
func AddWatermarks ¶
func AddWatermarks(rs io.ReadSeeker, w io.Writer, selectedPages []string, wm *pdf.Watermark, conf *pdf.Configuration) error
AddWatermarks adds watermarks to all pages selected in rs and writes the result to w.
func AddWatermarksFile ¶
func AddWatermarksFile(inFile, outFile string, selectedPages []string, wm *pdf.Watermark, conf *pdf.Configuration) (err error)
AddWatermarksFile adds watermarks to all selected pages of inFile and writes the result to outFile.
Example ¶
Output:
func ChangeOwnerPasswordFile ¶
func ChangeOwnerPasswordFile(inFile, outFile string, pwOld, pwNew string, conf *pdf.Configuration) error
ChangeOwnerPasswordFile reads inFile, changes the user password and writes the result to outFile. A configuration containing the current passwords is required.
Example ¶
Output:
func ChangeUserPasswordFile ¶
func ChangeUserPasswordFile(inFile, outFile string, pwOld, pwNew string, conf *pdf.Configuration) error
ChangeUserPasswordFile reads inFile, changes the user password and writes the result to outFile. A configuration containing the current passwords is required.
Example ¶
Output:
func CreatePDFFile ¶
CreatePDFFile creates a PDF file for an xRefTable and writes it to outFile.
func DecryptFile ¶
func DecryptFile(inFile, outFile string, conf *pdf.Configuration) error
DecryptFile decrypts inFile and writes the result to outFile. A configuration containing the current passwords is required.
Example ¶
Output:
func EncryptFile ¶
func EncryptFile(inFile, outFile string, conf *pdf.Configuration) error
EncryptFile encrypts inFile and writes the result to outFile. A configuration containing the current passwords is required.
Example ¶
Output:
func ExtractAttachments ¶
func ExtractAttachments(rs io.ReadSeeker, outDir string, fileNames []string, conf *pdf.Configuration) error
ExtractAttachments extracts embedded files from a PDF context read from rs into outDir.
func ExtractAttachmentsFile ¶
func ExtractAttachmentsFile(inFile, outDir string, fileNames []string, conf *pdf.Configuration) error
ExtractAttachmentsFile extracts embedded files from a PDF context read from inFile into outDir.
Example ¶
Output:
func ExtractContent ¶
func ExtractContent(rs io.ReadSeeker, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractContent dumps "PDF source" files from rs into outDir for selected pages.
func ExtractContentFile ¶
func ExtractContentFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractContentFile dumps "PDF source" files from inFile into outDir for selected pages.
Example ¶
Output:
func ExtractFonts ¶
func ExtractFonts(rs io.ReadSeeker, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractFonts dumps embedded fontfiles from rs into outDir for selected pages.
func ExtractFontsFile ¶
func ExtractFontsFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractFontsFile dumps embedded fontfiles from inFile into outDir for selected pages.
Example ¶
Output:
func ExtractImages ¶
func ExtractImages(rs io.ReadSeeker, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractImages dumps embedded image resources from rs into outDir for selected pages.
func ExtractImagesFile ¶
func ExtractImagesFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractImagesFile dumps embedded image resources from inFile into outDir for selected pages.
Example ¶
Output:
func ExtractMetadata ¶
func ExtractMetadata(rs io.ReadSeeker, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractMetadata dumps all metadata dict entries for rs into outDir.
func ExtractMetadataFile ¶
func ExtractMetadataFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractMetadataFile dumps all metadata dict entries for inFile into outDir.
Example ¶
Output:
func ExtractPages ¶
func ExtractPages(rs io.ReadSeeker, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractPages generates single page PDF files from rs in outDir for selected pages.
func ExtractPagesFile ¶
func ExtractPagesFile(inFile, outDir string, selectedPages []string, conf *pdf.Configuration) error
ExtractPagesFile generates single page PDF files from inFile in outDir for selected pages.
Example ¶
Output:
func HasWatermarks ¶
func HasWatermarks(rs io.ReadSeeker, conf *pdf.Configuration) (bool, error)
HasWatermarks checks rs for watermarks.
func HasWatermarksFile ¶
func HasWatermarksFile(inFile string, conf *pdf.Configuration) (bool, error)
HasWatermarksFile checks inFile for watermarks.
func ImportImages ¶
func ImportImages(rs io.ReadSeeker, w io.Writer, imgs []io.Reader, imp *pdf.Import, conf *pdf.Configuration) error
ImportImages appends PDF pages containing images to rs and writes the result to w. If rs == nil a new PDF file will be written to w.
func ImportImagesFile ¶
func ImportImagesFile(imgFiles []string, outFile string, imp *pdf.Import, conf *pdf.Configuration) (err error)
ImportImagesFile appends PDF pages containing images to outFile which will be created if necessary.
Example ¶
Output:
func Info ¶
func Info(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
Info returns information about rs.
func InfoFile ¶
func InfoFile(inFile string, conf *pdf.Configuration) ([]string, error)
InfoFile returns information about inFile.
func InsertPages ¶
func InsertPages(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
InsertPages inserts a blank page at every page selected of rs and writes the result to w.
func InsertPagesFile ¶
func InsertPagesFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
InsertPagesFile inserts a blank page at every inFile page selected and writes the result to w.
Example ¶
Output:
func ListAttachments ¶
func ListAttachments(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
ListAttachments returns a list of embedded file attachments of rs.
func ListAttachmentsFile ¶
func ListAttachmentsFile(inFile string, conf *pdf.Configuration) ([]string, error)
ListAttachmentsFile returns a list of embedded file attachments of inFile.
Example ¶
Output:
func ListPermissions ¶
func ListPermissions(rs io.ReadSeeker, conf *pdf.Configuration) ([]string, error)
ListPermissions returns a list of user access permissions.
func ListPermissionsFile ¶
func ListPermissionsFile(inFile string, conf *pdf.Configuration) ([]string, error)
ListPermissionsFile returns a list of user access permissions for inFile.
Example ¶
Output:
func Merge ¶
func Merge(rsc []io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
Merge merges a sequence of PDF streams and writes the result to w.
func MergeFile ¶
func MergeFile(inFiles []string, outFile string, conf *pdf.Configuration) error
MergeFile merges a sequence of inFiles and writes the result to outFile. This operation corresponds to file concatenation in the order specified by inFiles. The first entry of inFiles serves as the destination context where all remaining files get merged into.
Example ¶
Output:
func NUp ¶
func NUp(rs io.ReadSeeker, w io.Writer, imgFiles, selectedPages []string, nup *pdf.NUp, conf *pdf.Configuration) error
NUp rearranges PDF pages or images into page grids and writes the result to w. Either rs or imgFiles will be used.
func NUpFile ¶
func NUpFile(inFiles []string, outFile string, selectedPages []string, nup *pdf.NUp, conf *pdf.Configuration) (err error)
NUpFile rearranges PDF pages or images into page grids and writes the result to outFile.
Example ¶
Output:
func Optimize ¶
func Optimize(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
Optimize reads a PDF stream from rs and writes the optimized PDF stream to w.
func OptimizeContext ¶
OptimizeContext optimizes a PDF context.
func OptimizeFile ¶
func OptimizeFile(inFile, outFile string, conf *pdf.Configuration) (err error)
OptimizeFile reads inFile and writes the optimized PDF to outFile. If outFile is not provided then inFile gets overwritten which leads to the same result as when inFile equals outFile.
Example ¶
Output:
func PageCount ¶
func PageCount(rs io.ReadSeeker, conf *pdf.Configuration) (int, error)
PageCount returns rs's page count.
func PageCountFile ¶
PageCountFile returns inFile's page count.
func PageDims ¶
func PageDims(rs io.ReadSeeker, conf *pdf.Configuration) ([]pdf.Dim, error)
PageDims returns a sorted slice of mediaBox dimensions for rs.
func PageDimsFile ¶
PageDimsFile returns a sorted slice of mediaBox dimensions for inFile.
func ParsePageSelection ¶
ParsePageSelection ensures a correct page selection expression.
func ReadContext ¶
func ReadContext(rs io.ReadSeeker, conf *pdf.Configuration) (*pdf.Context, error)
ReadContext uses an io.ReadSeeker to build an internal structure holding its cross reference table aka the Context.
func ReadContextFile ¶
ReadContextFile returns inFile's validated context.
func RemoveAttachments ¶
func RemoveAttachments(rs io.ReadSeeker, w io.Writer, fileNames []string, conf *pdf.Configuration) error
RemoveAttachments deletes embedded files from a PDF context read from rs and writes the result to w.
func RemoveAttachmentsFile ¶
func RemoveAttachmentsFile(inFile, outFile string, files []string, conf *pdf.Configuration) (err error)
RemoveAttachmentsFile deletes embedded files from a PDF context read from inFile and writes the result to outFile.
Example ¶
Output:
func RemovePages ¶
func RemovePages(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
RemovePages removes selected pages from rs and writes the result to w.
func RemovePagesFile ¶
func RemovePagesFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
RemovePagesFile removes selected inFile pages and writes the result to outFile..
Example ¶
Output:
func RemoveWatermarks ¶
func RemoveWatermarks(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
RemoveWatermarks removes watermarks from all pages selected in rs and writes the result to w.
func RemoveWatermarksFile ¶
func RemoveWatermarksFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
RemoveWatermarksFile removes watermarks from all selected pages of inFile and writes the result to outFile.
Example ¶
Output:
func Rotate ¶
func Rotate(rs io.ReadSeeker, w io.Writer, rotation int, selectedPages []string, conf *pdf.Configuration) error
Rotate rotates selected pages of rs clockwise by rotation degrees and writes the result to w.
func RotateFile ¶
func RotateFile(inFile, outFile string, rotation int, selectedPages []string, conf *pdf.Configuration) (err error)
RotateFile rotates selected pages of inFile clockwise by rotation degrees and writes the result to outFile.
Example ¶
Output:
func SetPermissions ¶
func SetPermissions(rs io.ReadSeeker, w io.Writer, conf *pdf.Configuration) error
SetPermissions sets user access permissions. inFile has to be encrypted. A configuration containing the current passwords is required.
func SetPermissionsFile ¶
func SetPermissionsFile(inFile, outFile string, conf *pdf.Configuration) (err error)
SetPermissionsFile sets inFile's user access permissions. inFile has to be encrypted. A configuration containing the current passwords is required.
Example ¶
Output:
func Split ¶
func Split(rs io.ReadSeeker, outDir, fileName string, span int, conf *pdf.Configuration) error
Split generates a sequence of PDF files in outDir for the PDF stream read from rs obeying given split span. The default span 1 creates a sequence of single page PDFs.
func SplitFile ¶
func SplitFile(inFile, outDir string, span int, conf *pdf.Configuration) error
SplitFile generates a sequence of PDF files in outDir for inFile obeying given split span. The default span 1 creates a sequence of single page PDFs.
Example ¶
Output:
func Trim ¶
func Trim(rs io.ReadSeeker, w io.Writer, selectedPages []string, conf *pdf.Configuration) error
Trim generates a trimmed version of rs containing all selected pages and writes the result to w.
func TrimFile ¶
func TrimFile(inFile, outFile string, selectedPages []string, conf *pdf.Configuration) (err error)
TrimFile generates a trimmed version of inFile containing all selected pages and writes the result to outFile.
Example ¶
Output:
func Validate ¶
func Validate(rs io.ReadSeeker, conf *pdf.Configuration) error
Validate validates a PDF stream read from rs.
func ValidateContext ¶
ValidateContext validates a PDF context.
func ValidateFile ¶
func ValidateFile(inFile string, conf *pdf.Configuration) error
ValidateFile validates inFile.
Example ¶
Output:
func WatermarkContext ¶
WatermarkContext applies a watermark for selected pages,
func WriteContext ¶
WriteContext writes a PDF context to w.
Types ¶
type ReadSeekerCloser ¶
type ReadSeekerCloser interface { io.ReadSeeker io.Closer }
ReadSeekerCloser combines io.ReadSeeker and io.Closer