Class PdfConfiguration
-
- All Implemented Interfaces:
-
android.os.Parcelable
public final class PdfConfiguration implements Parcelable
The parameters
pageSize
,pageFit
,dpi
andresamplingMethod
interact in a complex way when adding bitmap images (JPEG, PNG, or raw) to the PDF. There are three cases to consider:pageSize
isCUSTOM
: in this casedpi
is used as the conversion ratio to calculate both the physical page and image sizes in inches from the bitmap dimensions.resamplingMethod
is ignored.pageSize
is notCUSTOM
ANDpageFit
isNONE
: in this casedpi
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.pageSize
is notCUSTOM
ANDpageFit
is notNONE
: 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 bypageFit
. 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 todpi
: 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 bypageFit
andpageSize
. b.resamplingMethod
is not NONE AND the calculated DPI is greater thandpi
: in this case the bitmap of the image is resampled to matchdpi
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.
-
-
Field Summary
Fields Modifier and Type Field Description private PdfAttributes
attributes
private PageSize
pageSize
private PageDirection
pageDirection
private PageFit
pageFit
private Integer
dpi
private Integer
jpegQuality
private ResamplingMethod
resamplingMethod
-
Constructor Summary
Constructors Constructor Description PdfConfiguration(Map<String, Object> source)
PdfConfiguration(JSONObject json)
PdfConfiguration(PdfAttributes attributes, PageSize pageSize, PageDirection pageDirection, PageFit pageFit, Integer dpi, Integer jpegQuality, ResamplingMethod resamplingMethod)
-
Method Summary
Modifier and Type Method Description final PdfAttributes
getAttributes()
Attributes. final Unit
setAttributes(PdfAttributes attributes)
Attributes. final PageSize
getPageSize()
Physical size of the page. final Unit
setPageSize(PageSize pageSize)
Physical size of the page. final PageDirection
getPageDirection()
Page direction. final Unit
setPageDirection(PageDirection pageDirection)
Page direction. final PageFit
getPageFit()
How to fit the image into the page. final Unit
setPageFit(PageFit pageFit)
How to fit the image into the page. final Integer
getDpi()
The dpi
parameter has two different meanings depending on the value ofpageSize
andpageFit
.final Unit
setDpi(Integer dpi)
The dpi
parameter has two different meanings depending on the value ofpageSize
andpageFit
.final Integer
getJpegQuality()
JPEG quality for images. final Unit
setJpegQuality(Integer jpegQuality)
JPEG quality for images. final ResamplingMethod
getResamplingMethod()
Resampling method. final Unit
setResamplingMethod(ResamplingMethod resamplingMethod)
Resampling method. final JSONObject
toJson(ToJsonConfiguration config)
final PdfConfiguration
clone()
final static PdfConfiguration
default()
-
-
Constructor Detail
-
PdfConfiguration
PdfConfiguration(JSONObject json)
-
PdfConfiguration
PdfConfiguration(PdfAttributes attributes, PageSize pageSize, PageDirection pageDirection, PageFit pageFit, Integer dpi, Integer jpegQuality, ResamplingMethod resamplingMethod)
-
-
Method Detail
-
getAttributes
final PdfAttributes getAttributes()
Attributes.
-
setAttributes
final Unit setAttributes(PdfAttributes attributes)
Attributes.
-
getPageSize
final PageSize getPageSize()
Physical size of the page. If CUSTOM, the page size will be set as the image size at given dpi.
Default is A4
-
setPageSize
final Unit setPageSize(PageSize pageSize)
Physical size of the page. If CUSTOM, the page size will be set as the image size at given dpi.
Default is A4
-
getPageDirection
final PageDirection getPageDirection()
Page direction.
Default is PORTRAIT
-
setPageDirection
final Unit setPageDirection(PageDirection pageDirection)
Page direction.
Default is PORTRAIT
-
getPageFit
final PageFit getPageFit()
How to fit the image into the page. Only used if
pageSize
is notCUSTOM
. 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
-
setPageFit
final Unit setPageFit(PageFit pageFit)
How to fit the image into the page. Only used if
pageSize
is notCUSTOM
. 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
-
getDpi
final Integer getDpi()
The
dpi
parameter has two different meanings depending on the value ofpageSize
andpageFit
. If pageSize is CUSTOM or pageFit is NONE, thendpi
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, ifresamplingMethod
is not NONE, then the image is downscaled if necessary (if the image after being fit to the page has a higher calculated DPI thandpi
) to matchdpi
before adding it to the PDF. Otherwise, the setting is ignored and the calculated image DPI is used instead.Default is 72
-
setDpi
final Unit setDpi(Integer dpi)
The
dpi
parameter has two different meanings depending on the value ofpageSize
andpageFit
. If pageSize is CUSTOM or pageFit is NONE, thendpi
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, ifresamplingMethod
is not NONE, then the image is downscaled if necessary (if the image after being fit to the page has a higher calculated DPI thandpi
) to matchdpi
before adding it to the PDF. Otherwise, the setting is ignored and the calculated image DPI is used instead.Default is 72
-
getJpegQuality
final Integer getJpegQuality()
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
-
setJpegQuality
final Unit setJpegQuality(Integer 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
-
getResamplingMethod
final ResamplingMethod getResamplingMethod()
Resampling method.
Default is NONE
-
setResamplingMethod
final Unit setResamplingMethod(ResamplingMethod resamplingMethod)
Resampling method.
Default is NONE
-
toJson
final JSONObject toJson(ToJsonConfiguration config)
-
clone
final PdfConfiguration clone()
-
default
final static PdfConfiguration default()
-
-
-
-