Class PdfConfiguration

java.lang.Object
io.scanbot.sdk.pdfgeneration.PdfConfiguration

public class PdfConfiguration extends Object
The parameters `pageSize`, `pageFit`, `dpi` and `resamplingMethod` interact in a complex way when adding bitmap images (JPEG, PNG, or raw) to the PDF. There are three cases to consider: 1. `pageSize` is `CUSTOM`: in this case `dpi` is used as the conversion ratio to calculate both the physical page and image sizes in inches from the bitmap dimensions. `resamplingMethod` is ignored. 2. `pageSize` is not `CUSTOM` AND `pageFit` is `NONE`: in this case `dpi` is used as the conversion ratio to calculate only the physical image size in inches from the bitmap dimensions. The image is centered onto the page. `resamplingMethod` is ignored. 3. `pageSize` is not `CUSTOM` AND `pageFit` is not `NONE`: in this case the page has a pre-determined physical size and we want to stretch the image to fit the page in one of the ways described by `pageFit`. The image DPI is automatically calculated for each image from the given physical page size, page fit setting and image dimensions. There are two sub-cases to consider: a. `resamplingMethod` is NONE OR the calculated DPI is less than or equal to `dpi`: in this case the image is added to the PDF without resampling, which means that the image rectangle is simply rescaled to fit into the page as specified by `pageFit` and `pageSize`. b. `resamplingMethod` is not NONE AND the calculated DPI is greater than `dpi`: in this case the bitmap of the image is resampled to match `dpi` using the selected method before adding it to the PDF. This will result in a bitmap that is smaller than the original image and hence, the resulting PDF will be smaller in size.
  • Constructor Details

    • PdfConfiguration

      public PdfConfiguration(PdfAttributes attributes, PageSize pageSize, PageDirection pageDirection, PageFit pageFit, int dpi, int jpegQuality, boolean jpegOptimize, ResamplingMethod resamplingMethod, ParametricFilter binarizationFilter)
      Constructs PdfConfiguration with the given params.
      Parameters:
      attributes - Attributes.
      pageSize - Physical size of the page. If CUSTOM, the page size will be set as the image size at given dpi. Default is `A4`.
      pageDirection - Page direction. Default is `PORTRAIT`.
      pageFit - How to fit the image into the page. Only used if `pageSize` is not `CUSTOM`. The image can either be stretched to fill the page, in one of three ways, or centered on the page without stretching. Default is `FIT_IN`.
      dpi - The `dpi` parameter has two different meanings depending on the value of `pageSize` and `pageFit`. If pageSize is CUSTOM or pageFit is NONE, then `dpi` is the conversion ratio used to convert from units of pixels to physical inches when adding bitmap images (JPEG, PNG, or raw) to the PDF. Otherwise, if `resamplingMethod` is not NONE, then the image is downscaled if necessary (if the image after being fit to the page has a higher calculated DPI than `dpi`) to match `dpi` before adding it to the PDF. Otherwise, the setting is ignored and the calculated image DPI is used instead. Default is `72`.
      jpegQuality - JPEG quality for images. Applies if an image is added as a cv::Mat and therefore needs to be encoded. Also applies if `resamplingMethod` not NONE and the image being added needs to be downscaled. Otherwise, when adding JPEG files to the PDF, the files are copied directly into the PDF and not re-encoded, which is many times faster and also preserves the quality of the original. Default is `80`.
      jpegOptimize - If `true`, the encoder will spend extra time when saving JPEG files to improve the compression rate. Enabling this option has no impact on quality. Enabling this flag always requires jpeg re-encoding even if input is already jpeg data. Default is `false`.
      resamplingMethod - Resampling method. Default is `NONE`.
      binarizationFilter - Filter to apply to the input image when adding pages with binarization.
    • PdfConfiguration

      public PdfConfiguration()
      Constructs PdfConfiguration with default parameters.
  • Method Details

    • getAttributes

      public PdfAttributes getAttributes()
      Getter for attributes field. See constructor documentation for more information about the field.
      Returns:
      attributes
    • setAttributes

      public void setAttributes(PdfAttributes attributes)
      Setter for attributes field. See constructor documentation for more information about the field.
      Parameters:
      attributes - Value to set.
    • getPageSize

      public PageSize getPageSize()
      Getter for pageSize field. See constructor documentation for more information about the field.
      Returns:
      pageSize
    • setPageSize

      public void setPageSize(PageSize pageSize)
      Setter for pageSize field. See constructor documentation for more information about the field.
      Parameters:
      pageSize - Value to set.
    • getPageDirection

      public PageDirection getPageDirection()
      Getter for pageDirection field. See constructor documentation for more information about the field.
      Returns:
      pageDirection
    • setPageDirection

      public void setPageDirection(PageDirection pageDirection)
      Setter for pageDirection field. See constructor documentation for more information about the field.
      Parameters:
      pageDirection - Value to set.
    • getPageFit

      public PageFit getPageFit()
      Getter for pageFit field. See constructor documentation for more information about the field.
      Returns:
      pageFit
    • setPageFit

      public void setPageFit(PageFit pageFit)
      Setter for pageFit field. See constructor documentation for more information about the field.
      Parameters:
      pageFit - Value to set.
    • getDpi

      public int getDpi()
      Getter for dpi field. See constructor documentation for more information about the field.
      Returns:
      dpi
    • setDpi

      public void setDpi(int dpi)
      Setter for dpi field. See constructor documentation for more information about the field.
      Parameters:
      dpi - Value to set.
    • getJpegQuality

      public int getJpegQuality()
      Getter for jpegQuality field. See constructor documentation for more information about the field.
      Returns:
      jpegQuality
    • setJpegQuality

      public void setJpegQuality(int jpegQuality)
      Setter for jpegQuality field. See constructor documentation for more information about the field.
      Parameters:
      jpegQuality - Value to set.
    • getJpegOptimize

      public boolean getJpegOptimize()
      Getter for jpegOptimize field. See constructor documentation for more information about the field.
      Returns:
      jpegOptimize
    • setJpegOptimize

      public void setJpegOptimize(boolean jpegOptimize)
      Setter for jpegOptimize field. See constructor documentation for more information about the field.
      Parameters:
      jpegOptimize - Value to set.
    • getResamplingMethod

      public ResamplingMethod getResamplingMethod()
      Getter for resamplingMethod field. See constructor documentation for more information about the field.
      Returns:
      resamplingMethod
    • setResamplingMethod

      public void setResamplingMethod(ResamplingMethod resamplingMethod)
      Setter for resamplingMethod field. See constructor documentation for more information about the field.
      Parameters:
      resamplingMethod - Value to set.
    • getBinarizationFilter

      public ParametricFilter getBinarizationFilter()
      Getter for binarizationFilter field. See constructor documentation for more information about the field.
      Returns:
      binarizationFilter
    • setBinarizationFilter

      public void setBinarizationFilter(ParametricFilter binarizationFilter)
      Setter for binarizationFilter field. See constructor documentation for more information about the field.
      Parameters:
      binarizationFilter - Value to set.