Interface PdfGenerationOptions

The parameters pageSize, pageFit, dpi and resample 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. resample 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. resample 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. resample is false 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. resample is true AND the calculated DPI is greater than dpi: in this case the bitmap of the image is resampled to match dpi 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.
interface PdfGenerationOptions {
    dpi?: number;
    jpegQuality?: number;
    pageDirection?: PageDirection;
    pageFit?: PageFit;
    resample?: boolean;
    standardPaperSize?: PageSize;
}

Properties

dpi?: number

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 resample is true, 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 value: 72

jpegQuality?: number

JPEG quality for images. Applies if an image is added as a cv::Mat and therefore needs to be encoded. Also applies if resample is true 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 value: 80

pageDirection?: PageDirection

Default value: PORTRAIT

pageFit?: 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 value: FIT_IN

resample?: boolean

false: always geometrically rescale the image to fit the page if necessary. Fast. true: downscale the bitmap to match the dpi setting before adding it to the PDF if the calculated image DPI after stretching is greater than dpi. Slower. Default value: false

standardPaperSize?: PageSize

Physical size of the page. If CUSTOM, the page size will be set as the image size at given dpi. Default value: A4

Generated using TypeDoc