PdfRenderConfig

Struct PdfRenderConfig 

Source
pub struct PdfRenderConfig { /* private fields */ }
Expand description

Configures the scaling, rotation, and rendering settings that should be applied to a PdfPage to create a PdfBitmap for that page. PdfRenderConfig can accommodate pages of different sizes while correctly maintaining each page’s aspect ratio, automatically rotate portrait or landscape pages, generate page thumbnails, apply maximum and minimum pixel sizes to the scaled width and height of the final bitmap, highlight form fields with different colors, apply custom transforms to the page during rendering, and set internal Pdfium rendering flags.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Implementations§

Source§

impl PdfRenderConfig

Source

pub fn new() -> Self

Creates a new PdfRenderConfig object with all settings initialized with their default values.

Source

pub fn thumbnail(self, size: Pixels) -> Self

Applies settings suitable for generating a thumbnail.

  • The source PdfPage will be rendered with a maximum width and height of the given pixel size.
  • The page will not be rotated, irrespective of its orientation.
  • Image quality settings will be reduced to improve performance.
  • Annotations and user-filled form field data will not be rendered.

These settings are applied to this PdfRenderConfig object immediately and can be selectively overridden by later function calls. For instance, a later call to PdfRenderConfig::rotate() can specify a custom rotation setting that will apply to the thumbnail.

Source

pub fn set_target_size(self, width: Pixels, height: Pixels) -> Self

Converts the width and height of a PdfPage from points to pixels, scaling each dimension to the given target pixel sizes. The aspect ratio of the source page will not be maintained.

Source

pub fn set_target_width(self, width: Pixels) -> Self

Converts the width of a PdfPage from points to pixels, scaling the source page width to the given target pixel width. The aspect ratio of the source page will be maintained so long as there is no call to PdfRenderConfig::set_target_size() or PdfRenderConfig::set_target_height() that overrides it.

Source

pub fn set_target_height(self, height: Pixels) -> Self

Converts the height of a PdfPage from points to pixels, scaling the source page height to the given target pixel height. The aspect ratio of the source page will be maintained so long as there is no call to PdfRenderConfig::set_target_size() or PdfRenderConfig::set_target_width() that overrides it.

Source

pub fn scale_page_to_display_size(self, width: Pixels, height: Pixels) -> Self

Applies settings to this PdfRenderConfig suitable for filling the given screen display size.

The source page’s dimensions will be scaled so that both width and height attempt to fill, but do not exceed, the given pixel dimensions. The aspect ratio of the source page will be maintained. Landscape pages will be automatically rotated by 90 degrees and will be scaled down if necessary to fit the display width.

Source

pub fn scale_page_by_factor(self, scale: f32) -> Self

Converts the width and height of a PdfPage from points to pixels by applying the given scale factor to both dimensions. The aspect ratio of the source page will be maintained. Overrides any previous call to PdfRenderConfig::scale_page_by_factor(), PdfRenderConfig::scale_page_width_by_factor(), or PdfRenderConfig::scale_page_height_by_factor().

Source

pub fn scale_page_width_by_factor(self, scale: f32) -> Self

Converts the width of the PdfPage from points to pixels by applying the given scale factor. The aspect ratio of the source page will not be maintained if a different scale factor is applied to the height. Overrides any previous call to PdfRenderConfig::scale_page_by_factor(), PdfRenderConfig::scale_page_width_by_factor(), or PdfRenderConfig::scale_page_height_by_factor().

Source

pub fn scale_page_height_by_factor(self, scale: f32) -> Self

Converts the height of the PdfPage from points to pixels by applying the given scale factor. The aspect ratio of the source page will not be maintained if a different scale factor is applied to the width. Overrides any previous call to PdfRenderConfig::scale_page_by_factor(), PdfRenderConfig::scale_page_width_by_factor(), or PdfRenderConfig::scale_page_height_by_factor().

Source

pub fn set_maximum_width(self, width: Pixels) -> Self

Specifies that the final pixel width of the PdfPage will not exceed the given maximum.

Source

pub fn set_maximum_height(self, height: Pixels) -> Self

Specifies that the final pixel height of the PdfPage will not exceed the given maximum.

Source

pub fn rotate( self, rotation: PdfPageRenderRotation, do_rotate_constraints: bool, ) -> Self

Applies the given clockwise rotation setting to the PdfPage during rendering, irrespective of its orientation. If the given flag is set to true then any maximum constraint on the final pixel width set by a call to PdfRenderConfig::set_maximum_width() will be rotated so it becomes a constraint on the final pixel height, and any maximum constraint on the final pixel height set by a call to PdfRenderConfig::set_maximum_height() will be rotated so it becomes a constraint on the final pixel width.

Source

pub fn rotate_if_portrait( self, rotation: PdfPageRenderRotation, do_rotate_constraints: bool, ) -> Self

Applies the given clockwise rotation settings to the PdfPage during rendering, if the page is in portrait orientation. If the given flag is set to true and the given rotation setting is PdfPageRenderRotation::Degrees90 or PdfPageRenderRotation::Degrees270 then any maximum constraint on the final pixel width set by a call to PdfRenderConfig::set_maximum_width() will be rotated so it becomes a constraint on the final pixel height and any maximum constraint on the final pixel height set by a call to PdfRenderConfig::set_maximum_height() will be rotated so it becomes a constraint on the final pixel width.

Source

pub fn rotate_if_landscape( self, rotation: PdfPageRenderRotation, do_rotate_constraints: bool, ) -> Self

Applies the given rotation settings to the PdfPage during rendering, if the page is in landscape orientation. If the given flag is set to true and the given rotation setting is PdfPageRenderRotation::Degrees90 or PdfPageRenderRotation::Degrees270 then any maximum constraint on the final pixel width set by a call to PdfRenderConfig::set_maximum_width() will be rotated so it becomes a constraint on the final pixel height and any maximum constraint on the final pixel height set by a call to PdfRenderConfig::set_maximum_height() will be rotated so it becomes a constraint on the final pixel width.

Source

pub fn set_format(self, format: PdfBitmapFormat) -> Self

Sets the pixel format that will be used during rendering of the PdfPage. The default is PdfBitmapFormat::BGRA.

Source

pub fn clear_before_rendering(self, do_clear: bool) -> Self

Controls whether the destination bitmap should be cleared by setting every pixel to a known color value before rendering the PdfPage. The default is true. The color used during clearing can be customised by calling PdfRenderConfig::set_clear_color().

Source

pub fn set_clear_color(self, color: PdfColor) -> Self

Sets the color applied to every pixel in the destination bitmap when clearing the bitmap before rendering the PdfPage. The default is PdfColor::WHITE. This setting has no effect if PdfRenderConfig::clear_before_rendering() is set to false.

Source

pub fn render_form_data(self, do_render: bool) -> Self

Controls whether form data widgets and user-supplied form data should be included during rendering of the PdfPage. The default is true.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically sets this value to false, disabling rendering of form data.

Source

pub fn render_annotations(self, do_render: bool) -> Self

Controls whether user-supplied annotations should be included during rendering of the PdfPage. The default is true.

Source

pub fn use_lcd_text_rendering(self, do_set_flag: bool) -> Self

Controls whether text rendering should be optimized for LCD display. The default is false. Has no effect if anti-aliasing of text has been disabled by a call to PdfRenderConfig::set_text_smoothing(false).

Source

pub fn disable_native_text_rendering(self, do_set_flag: bool) -> Self

Controls whether platform text rendering should be disabled on platforms that support it. The alternative is for Pdfium to render all text internally, which may give more consistent rendering results across platforms but may also be slower. The default is false.

Source

pub fn use_grayscale_rendering(self, do_set_flag: bool) -> Self

Controls whether rendering output should be grayscale rather than full color. The default is false.

Source

pub fn limit_render_image_cache_size(self, do_set_flag: bool) -> Self

Controls whether Pdfium should limit its image cache size during rendering. A smaller cache size may result in lower memory usage at the cost of slower rendering. The default is false.

Source

pub fn force_half_tone(self, do_set_flag: bool) -> Self

Controls whether Pdfium should always use halftone for image stretching. Halftone image stretching is often higher quality than linear image stretching but is much slower. The default is false.

Source

pub fn use_print_quality(self, do_set_flag: bool) -> Self

Controls whether Pdfium should render for printing. The default is false.

Certain PDF files may stipulate different quality settings for on-screen display compared to printing. For these files, changing this setting to true will result in a higher quality rendered bitmap but slower performance. For PDF files that do not stipulate different quality settings, changing this setting will have no effect.

Source

pub fn set_text_smoothing(self, do_set_flag: bool) -> Self

Controls whether rendered text should be anti-aliased. The default is true. The enabling of LCD-optimized text rendering via a call to PdfiumBitmapConfig::use_lcd_text_rendering(true) has no effect if this flag is set to false.

Source

pub fn set_image_smoothing(self, do_set_flag: bool) -> Self

Controls whether rendered images should be anti-aliased. The default is true.

Source

pub fn set_path_smoothing(self, do_set_flag: bool) -> Self

Controls whether rendered vector paths should be anti-aliased. The default is true.

Source

pub fn set_reverse_byte_order(self, do_set_flag: bool) -> Self

Controls whether the byte order of generated image data should be reversed during rendering. The default is true, so that Pdfium returns pixel data as four-channel RGBA rather than its default of four-channel BGRA.

There should generally be no need to change this flag unless you want to do raw image processing and specifically need the pixel data returned by the PdfBitmap::as_raw_bytes() function to be in BGR8 format.

Source

pub fn render_fills_as_strokes(self, do_set_flag: bool) -> Self

Controls whether rendered vector fill paths need to be stroked. The default is false.

Source

pub fn highlight_all_form_fields(self, color: PdfColor) -> Self

Highlights all rendered form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_button_form_fields(self, color: PdfColor) -> Self

Highlights all rendered push button form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_checkbox_form_fields(self, color: PdfColor) -> Self

Highlights all rendered checkbox form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_radio_button_form_fields(self, color: PdfColor) -> Self

Highlights all rendered radio button form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_combobox_form_fields(self, color: PdfColor) -> Self

Highlights all rendered combobox form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_listbox_form_fields(self, color: PdfColor) -> Self

Highlights all rendered listbox form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_text_form_fields(self, color: PdfColor) -> Self

Highlights all rendered text entry form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_signature_form_fields(self, color: PdfColor) -> Self

Highlights all rendered signature form fields with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn highlight_form_fields_of_type( self, form_field_type: PdfFormFieldType, color: PdfColor, ) -> Self

Highlights all rendered form fields matching the given type with the given color. Note that specifying a solid color with no opacity will overprint any user data in the field.

Source

pub fn transform( self, a: PdfMatrixValue, b: PdfMatrixValue, c: PdfMatrixValue, d: PdfMatrixValue, e: PdfMatrixValue, f: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Applies the given transformation, expressed as six values representing the six configurable elements of a nine-element 3x3 PDF transformation matrix, to the PdfPage during rendering.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

To move, scale, rotate, or skew the PdfPage during rendering, consider using one or more of the following functions. Internally they all use Self::transform(), but are probably easier to use (and certainly clearer in their intent) in most situations.

The order in which transformations are applied is significant. For example, the result of rotating then translating an object may be vastly different from translating then rotating the same object.

An overview of PDF transformation matrices can be found in the PDF Reference Manual version 1.7 on page 204; a detailed description can be found in section 4.2.3 on page 207.

Source

pub fn apply_matrix(self, matrix: PdfMatrix) -> Result<Self, PdfiumError>

Applies the given transformation, expressed as a PdfMatrix, to the PdfPage during rendering.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn reset_matrix(self, matrix: PdfMatrix) -> Result<Self, PdfiumError>

Resets the transform matrix for the PdfPage during rendering to the the given PdfMatrix, overriding any previously applied transformations.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn reset_matrix_to_identity(self) -> Result<Self, PdfiumError>

Resets the transformation matrix for the PdfPage during rendering to the identity matrix, undoing any previously applied transformations.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn translate( self, delta_x: PdfPoints, delta_y: PdfPoints, ) -> Result<Self, PdfiumError>

Moves the origin of the PdfPage during rendering by the given horizontal and vertical delta distances.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn scale( self, horizontal_scale_factor: PdfMatrixValue, vertical_scale_factor: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Changes the size of the PdfPage during rendering, scaling it by the given horizontal and vertical scale factors.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn flip_horizontally(self) -> Result<Self, PdfiumError>

Flips the PdfPage during rendering horizontally around its origin by applying a horizontal scale factor of -1.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn flip_vertically(self) -> Result<Self, PdfiumError>

Flips the PdfPage during rendering vertically around its origin by applying a vertical scale factor of -1.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn reflect(self) -> Result<Self, PdfiumError>

Reflects the PdfPage during rendering by flipping it both horizontally and vertically around its origin.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn rotate_counter_clockwise_degrees( self, degrees: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Rotates the PdfPage during rendering counter-clockwise by the given number of degrees.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn rotate_clockwise_degrees( self, degrees: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Rotates the PdfPage during rendering clockwise by the given number of degrees.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn rotate_counter_clockwise_radians( self, radians: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Rotates the PdfPage during rendering counter-clockwise by the given number of radians.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn rotate_clockwise_radians( self, radians: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Rotates the PdfPage during rendering clockwise by the given number of radians.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn skew_degrees( self, x_axis_skew: PdfMatrixValue, y_axis_skew: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Skews the axes of the PdfPage during rendering by the given angles in degrees.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn skew_radians( self, x_axis_skew: PdfMatrixValue, y_axis_skew: PdfMatrixValue, ) -> Result<Self, PdfiumError>

Skews the axes of the PdfPage during rendering by the given angles in radians.

Pdfium’s rendering pipeline supports either rendering with form data or rendering with a custom transformation matrix, but not both at the same time. Applying any transformation automatically disables rendering of form data. If you must render form data while simultaneously applying transformations, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Source

pub fn clip( self, left: Pixels, top: Pixels, right: Pixels, bottom: Pixels, ) -> Self

Clips rendering output to the given pixel coordinates. Pdfium will not render outside the clipping area; any existing image data in the destination PdfBitmap will remain intact.

Pdfium’s rendering pipeline supports either rendering with form data or clipping rendering output, but not both at the same time. Applying a clipping rectangle automatically disables rendering of form data. If you must render form data while simultaneously applying a clipping rectangle, consider using the PdfPage::flatten() function to flatten the form elements and form data into the containing page.

Trait Implementations§

Source§

impl Default for PdfRenderConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.