...

Package pdfutil

Overview ▾

func ConvertPageToGrayscale

func ConvertPageToGrayscale(page *model.PdfPage) error

ConvertPageToGrayscale() replaces color objects on the page with grayscale ones. Also references XObject Images and Forms to convert those to grayscale.

func ExtractPageRange

func ExtractPageRange(inputPath string, outputPath string, pageFrom int, pageTo int, keepOptionalContent bool) error

ExtractPageRange extracts a range of pages from inputPath PDF file and saves it as outputPath PDF file. keepOptionalContent controls if we need to process OC properties (rarely needed).

func MergePdf

func MergePdf(inputPaths []string, outputPath string, isMergingForms bool) error

MergePdf merges several PDF files passed as inputPaths to one PDF file, outputPath. isMergingForms controls if it is necessary to merge AcroForms from input files. If you are not sure, you can always set isMergingForms to true.

func MergePdfStreams

func MergePdfStreams(inputs []io.ReadSeeker, output io.Writer, isMergingForms bool) error

MergePdfStreams merges several PDF streams passed as io.ReadSeeker and writes the result to output. isMergingForms controls if it is necessary to merge AcroForms from input streams. If you are not sure, you can always set isMergingForms to true.

func MergePdfStreamsWithOptions

func MergePdfStreamsWithOptions(inputs []io.ReadSeeker, output io.Writer, opts MergePdfOptions) error

MergePdfStreamsWithOptions merges several PDF streams and writes the result to output, applying the supplied options. See MergePdfOptions for available knobs.

func MergePdfWithFilePermission

func MergePdfWithFilePermission(inputPaths []string, outputPath string, isMergingForms bool, perm os.FileMode) error

MergePdfWithFilePermission merges several PDF files passed as inputPaths to one PDF file, outputPath. isMergingForms controls if it is necessary to merge AcroForms from input files. If you are not sure, you can always set isMergingForms to true. perm sets the file permission for the output file.

func MergePdfWithFilePermissionAndOptions

func MergePdfWithFilePermissionAndOptions(inputPaths []string, outputPath string, opts MergePdfOptions, perm os.FileMode) error

MergePdfWithFilePermissionAndOptions merges several PDF files passed as inputPaths to one PDF file, outputPath, applying the supplied options and writing the result with the given file permission. See MergePdfOptions for available knobs.

func MergePdfWithOptions

func MergePdfWithOptions(inputPaths []string, outputPath string, opts MergePdfOptions) error

MergePdfWithOptions merges several PDF files passed as inputPaths to one PDF file, outputPath, applying the supplied options. See MergePdfOptions for available knobs.

func NormalizePage

func NormalizePage(page *model.PdfPage) error

NormalizePage performs the following operations on the passed in page:

- Normalize the page rotation.
  Rotates the contents of the page according to the Rotate entry, thus
  flattening the rotation. The Rotate entry of the page is set to nil.
- Normalize the media box.
  If the media box of the page is offsetted (Llx != 0 or Lly != 0),
  the contents of the page are translated to (-Llx, -Lly). After
  normalization, the media box is updated (Llx and Lly are set to 0 and
  Urx and Ury are updated accordingly).
- Normalize the crop box.
  The crop box of the page is updated based on the previous operations.

After normalization, the page should look the same if openend using a PDF viewer. NOTE: This function does not normalize annotations, outlines other parts that are not part of the basic geometry and page content streams.

type MergePdfOptions

MergePdfOptions configures behaviour of the merge operation.

type MergePdfOptions struct {
    // IsMergingForms controls whether AcroForms from input documents are merged.
    IsMergingForms bool

    // Optimizer is applied to the merged document on write. When nil (default),
    // the merged output is written without optimization. To deduplicate streams
    // shared across input documents (e.g. embedded font programs, image
    // XObjects, ToUnicode CMaps), pass
    // optimize.New(optimize.Options{CombineDuplicateStreams: true}).
    Optimizer model.Optimizer
}