PTFlattener

@interface PTFlattener : NSObject

Flattener is a optional PDFNet add-on that can be used to simplify and optimize existing PDF’s to render faster on devices with lower memory and speeds.

PDF documents can frequently contain very complex page description (e.g. thousands of paths, different shadings, color spaces, blend modes, large images etc.) that may not be suitable for interactive viewing on mobile devices. Flattener can be used to speed-up PDF rendering on mobile devices and on the Web by simplifying page content (e.g. flattening complex graphics into images) while maintaining vector text whenever possible.

By using the FlattenMode::e_simple option each page in the PDF will be reduced to a single background image, with the remaining text over top in vector format. Some text may still get flattened, in particular any text that is clipped, or underneath, other content that will be flattened.

On the other hand the FlattenMode::e_fast will not flatten simple content, such as simple straight lines, nor will it flatten Type3 fonts.

Note

‘Flattener’ is available as a separately licensable add-on to PDFNet core license.

Note

See ‘pdftron.PDF.Optimizer’ for alternate approach to optimize PDFs with focus on file size reduction.

  • Flattener constructor

    Declaration

    Objective-C

    - (instancetype)init;

    Swift

    init!()
  • The output resolution, from 1 to 1000, in Dots Per Inch (DPI) at which to render elements which cannot be directly converted. the default value is 150 Dots Per Inch

    Declaration

    Objective-C

    - (void)SetDPI:(unsigned int)dpi;

    Swift

    func setDPI(_ dpi: UInt32)

    Parameters

    dpi

    the resolution in Dots Per Inch

  • Specifies the maximum image size in pixels.

    Declaration

    Objective-C

    - (void)SetMaximumImagePixels:(unsigned int)max_pixels;

    Swift

    func setMaximumImagePixels(_ max_pixels: UInt32)

    Parameters

    max_pixels

    the maximum number of pixels an image can have.

  • Specifies whether to leave images in existing compression, or as JPEG.

    Declaration

    Objective-C

    - (void)SetPreferJPG:(BOOL)jpg;

    Swift

    func setPreferJPG(_ jpg: Bool)

    Parameters

    jpg

    if true PDF will contain all JPEG images.

  • Specifies the compression quality to use when generating JPEG images.

    Declaration

    Objective-C

    - (void)SetJPGQuality:(unsigned int)quality;

    Swift

    func setJPGQuality(_ quality: UInt32)

    Parameters

    quality

    the JPEG compression quality, from 0(highest compression) to 100(best quality).

  • Used to control how precise or relaxed text flattening is. When some text is preserved (not flattened to image) the visual appearance of the document may be altered.

    Declaration

    Objective-C

    - (void)SetThreshold:(PTThreshold)threshold;

    Swift

    func setThreshold(_ threshold: PTThreshold)

    Parameters

    threshold

    the threshold setting to use.

  • Enable or disable path hinting.

    Declaration

    Objective-C

    - (void)SetPathHinting:(BOOL)enable_hinting;

    Swift

    func setPathHinting(_ enable_hinting: Bool)

    Parameters

    enable_hinting

    if true path hinting is enabled. Path hinting is used to slightly adjust paths in order to avoid or alleviate artifacts of hair line cracks between certain graphical elements. This option is turned on by default.

  • Process each page in the PDF, flattening content that matches the mode criteria.

    Declaration

    Objective-C

    - (void)Process:(PTPDFDoc *)doc mode:(PTFlattenMode)mode;

    Swift

    func process(_ doc: PTPDFDoc!, mode: PTFlattenMode)

    Parameters

    doc

    the document to flatten.

    mode

    indicates the criteria for which elements are flattened.