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

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    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

                func CreatePDFFile(xRefTable *pdf.XRefTable, outFile string, conf *pdf.Configuration) error

                  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 FontNames

                                              func FontNames() []string

                                                FontNames returns a list of supported fonts.

                                                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

                                                                                  func OptimizeContext(ctx *pdf.Context) error

                                                                                    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

                                                                                        func PageCountFile(inFile string) (int, error)

                                                                                          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

                                                                                            func PageDimsFile(inFile string) ([]pdf.Dim, error)

                                                                                              PageDimsFile returns a sorted slice of mediaBox dimensions for inFile.

                                                                                              func ParsePageSelection

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

                                                                                                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

                                                                                                  func ReadContextFile(inFile string) (*pdf.Context, error)

                                                                                                    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

                                                                                                                                  func ValidateContext(ctx *pdf.Context) error

                                                                                                                                    ValidateContext validates a PDF context.

                                                                                                                                    func ValidateFile

                                                                                                                                    func ValidateFile(inFile string, conf *pdf.Configuration) error

                                                                                                                                      ValidateFile validates inFile.

                                                                                                                                      Example
                                                                                                                                      Output:
                                                                                                                                      
                                                                                                                                      

                                                                                                                                      func WatermarkContext

                                                                                                                                      func WatermarkContext(ctx *pdf.Context, selectedPages pdf.IntSet, wm *pdf.Watermark) error

                                                                                                                                        WatermarkContext applies a watermark for selected pages,

                                                                                                                                        func WriteContext

                                                                                                                                        func WriteContext(ctx *pdf.Context, w io.Writer) error

                                                                                                                                          WriteContext writes a PDF context to w.

                                                                                                                                          func WriteContextFile

                                                                                                                                          func WriteContextFile(ctx *pdf.Context, outFile string) error

                                                                                                                                            WriteContextFile writes a PDF context to outFile.

                                                                                                                                            Types

                                                                                                                                            type ReadSeekerCloser

                                                                                                                                            type ReadSeekerCloser interface {
                                                                                                                                            	io.ReadSeeker
                                                                                                                                            	io.Closer
                                                                                                                                            }

                                                                                                                                              ReadSeekerCloser combines io.ReadSeeker and io.Closer