Show / Hide Table of Contents

# Class Flattener

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 or for use via Cloud API (http://www.pdftron.com/pdfnet/cloud).

@note See 'pdftron.PDF.Optimizer' for alternate approach to optimize PDFs with focus on file size reduction.

##### Inheritance

object
Flattener

##### Implements

IDisposable

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: pdftron.PDF

###### Assembly: PDFTronDotNet.dll

##### Syntax

    public class Flattener : IDisposable

### Constructors

#### Flattener()

Flattener constructor

##### Declaration

    public Flattener()

### Methods

#### Destroy()

##### Declaration

    public void Destroy()

#### Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

##### Declaration

    public void Dispose()

#### Dispose(bool)

##### Declaration

    protected virtual void Dispose(bool disposing)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | disposing |

#### ~Flattener()

##### Declaration

    protected ~Flattener()

#### Process(PDFDoc, FlattenMode)

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

##### Declaration

    public void Process(PDFDoc doc, Flattener.FlattenMode mode)

##### Parameters

Type | Name | Description
--- | --- | ---
PDFDoc | doc | the document to flatten.
Flattener.FlattenMode | mode | indicates the criteria for which elements are flattened.

#### Process(Page, FlattenMode)

Process the given page, flattening content that matches the mode criteria.

##### Declaration

    public void Process(Page page, Flattener.FlattenMode mode)

##### Parameters

Type | Name | Description
--- | --- | ---
Page | page | the page to flatten.
Flattener.FlattenMode | mode | indicates the criteria for which elements are flattened.

#### SetDPI(uint)

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 96 Dots Per Inch

##### Declaration

    public void SetDPI(uint dpi)

##### Parameters

Type | Name | Description
--- | --- | ---
uint | dpi | the resolution in Dots Per Inch

#### SetJPGQuality(uint)

Specifies the compression quality to use when generating JPEG images.

##### Declaration

    public void SetJPGQuality(uint quality)

##### Parameters

Type | Name | Description
--- | --- | ---
uint | quality | the JPEG compression quality, from 0(highest compression) to 100(best quality).

#### SetMaximumImagePixels(uint)

Specifies the maximum image size in pixels.

##### Declaration

    public void SetMaximumImagePixels(uint max_pixels)

##### Parameters

Type | Name | Description
--- | --- | ---
uint | max_pixels | the maximum number of pixels an image can have.

#### SetPathHinting(bool)

Enable or disable path hinting.

##### Declaration

    public void SetPathHinting(bool path_hinting)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | path_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.

#### SetPreferJPG(bool)

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

##### Declaration

    public void SetPreferJPG(bool jpg)

##### Parameters

Type | Name | Description
--- | --- | ---
bool | jpg | if true PDF will contain all JPEG images.

#### SetThreshold(Threshold)

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

    public void SetThreshold(Flattener.Threshold threshold)

##### Parameters

Type | Name | Description
--- | --- | ---
Flattener.Threshold | threshold | the threshold setting to use.

### Implements

IDisposable