new 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.
Note: See 'pdftron.PDF.Optimizer' for alternate approach to optimize PDFs with
focus on file size reduction.
Extends
Members
-
<static> Mode
-
Type:
- number
Properties:
Name Type Description e_simple
number e_fast
number -
<static> Threshold
-
Type:
- number
Properties:
Name Type Description e_very_strict
number e_strict
number e_default
number e_keep_most
number e_keep_all
number
Methods
-
<static> create()
-
Flattener constructor
Returns:
A promise that resolves to an object of type: "PDFNet.Flattener"- Type
- Promise.<PDFNet.Flattener>
-
destroy()
-
Destructor
- Inherited From:
Returns:
- Type
- Promise.<void>
-
process(doc, mode)
-
Process each page in the PDF, flattening content that matches the mode criteria.
Parameters:
Name Type Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc the document to flatten. mode
number PDFNet.Flattener.Mode = { e_simple : 0 e_fast : 1 }
indicates the criteria for which elements are flattened.Returns:
- Type
- Promise.<void>
-
processPage(page, mode)
-
Process the given page, flattening content that matches the mode criteria.
Parameters:
Name Type Description page
PDFNet.Page the page to flatten. mode
number PDFNet.Flattener.Mode = { e_simple : 0 e_fast : 1 }
indicates the criteria for which elements are flattened.Returns:
- Type
- Promise.<void>
-
setDPI(dpi)
-
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
Parameters:
Name Type Description dpi
number the resolution in Dots Per Inch Returns:
- Type
- Promise.<void>
-
setJPGQuality(quality)
-
Specifies the compression quality to use when generating JPEG images.
Parameters:
Name Type Description quality
number the JPEG compression quality, from 0(highest compression) to 100(best quality). Returns:
- Type
- Promise.<void>
-
setMaximumImagePixels(max_pixels)
-
Specifies the maximum image size in pixels.
Parameters:
Name Type Description max_pixels
number the maximum number of pixels an image can have. Returns:
- Type
- Promise.<void>
-
setPathHinting(hinting)
-
Enable or disable path hinting.
Parameters:
Name Type Description hinting
boolean 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. Returns:
- Type
- Promise.<void>
-
setPreferJPG(jpg)
-
Specifies whether to leave images in existing compression, or as JPEG.
Parameters:
Name Type Description jpg
boolean if true PDF will contain all JPEG images. Returns:
- Type
- Promise.<void>
-
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.
Parameters:
Name Type Description threshold
number PDFNet.Flattener.Threshold = { e_very_strict : 0 e_strict : 1 e_default : 2 e_keep_most : 3 e_keep_all : 4 }
the threshold setting to use.Returns:
- Type
- Promise.<void>
-
takeOwnership()
-
Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
- Inherited From:
Returns:
- Type
- void