Module: pdfjsLib

Source:

Classes

PDFDataRangeTransport
PDFDocumentLoadingTask
PDFDocumentProxy
PDFObjects
PDFPageProxy
PDFWorker
RenderTask

Members

(inner, constant) build :string

Type:
  • string
Source:

(inner, constant) version :string

Type:
  • string
Source:

Methods

(inner) getDocument(src) → {PDFDocumentLoadingTask}

This is the main entry point for loading a PDF and interacting with it. NOTE: If a URL is used to fetch the PDF data a standard Fetch API call (or XHR as fallback) is used, which means it must follow same origin rules, e.g. no cross-domain requests without CORS.
Parameters:
Name Type Description
src string | URL | TypedArray | ArrayBuffer | DocumentInitParameters Can be a URL where a PDF file is located, a typed array (Uint8Array) already populated with data, or a parameter object.
Source:
Returns:
Type
PDFDocumentLoadingTask

Type Definitions

DocumentInitParameters

Document initialization / loading parameters object.
Type:
  • Object
Properties:
Name Type Attributes Description
url string | URL <optional>
The URL of the PDF.
data TypedArray | ArrayBuffer | Array:.<number:> | string <optional>
Binary PDF data. Use TypedArrays (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded, use `atob()` to convert it to a binary string first. NOTE: If TypedArrays are used they will generally be transferred to the worker-thread. This will help reduce main-thread memory usage, however it will take ownership of the TypedArrays.
httpHeaders Object <optional>
Basic authentication headers.
withCredentials boolean <optional>
Indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies or authorization headers. The default is `false`.
password string <optional>
For decrypting password-protected PDFs.
length number <optional>
The PDF file length. It's used for progress reports and range requests operations.
range PDFDataRangeTransport <optional>
Allows for using a custom range transport implementation.
rangeChunkSize number <optional>
Specify maximum number of bytes fetched per range request. The default value is DEFAULT_RANGE_CHUNK_SIZE.
worker PDFWorker <optional>
The worker that will be used for loading and parsing the PDF data.
verbosity number <optional>
Controls the logging level; the constants from VerbosityLevel should be used.
docBaseUrl string <optional>
The base URL of the document, used when attempting to recover valid absolute URLs for annotations, and outline items, that (incorrectly) only specify relative URLs.
cMapUrl string <optional>
The URL where the predefined Adobe CMaps are located. Include the trailing slash.
cMapPacked boolean <optional>
Specifies if the Adobe CMaps are binary packed or not. The default value is `true`.
CMapReaderFactory Object <optional>
The factory that will be used when reading built-in CMap files. Providing a custom factory is useful for environments without Fetch API or `XMLHttpRequest` support, such as Node.js. The default value is {DOMCMapReaderFactory}.
useSystemFonts boolean <optional>
When `true`, fonts that aren't embedded in the PDF document will fallback to a system font. The default value is `true` in web environments and `false` in Node.js; unless `disableFontFace === true` in which case this defaults to `false` regardless of the environment (to prevent completely broken fonts).
standardFontDataUrl string <optional>
The URL where the standard font files are located. Include the trailing slash.
StandardFontDataFactory Object <optional>
The factory that will be used when reading the standard font files. Providing a custom factory is useful for environments without Fetch API or `XMLHttpRequest` support, such as Node.js. The default value is {DOMStandardFontDataFactory}.
useWorkerFetch boolean <optional>
Enable using the Fetch API in the worker-thread when reading CMap and standard font files. When `true`, the `CMapReaderFactory` and `StandardFontDataFactory` options are ignored. The default value is `true` in web environments and `false` in Node.js.
stopAtErrors boolean <optional>
Reject certain promises, e.g. `getOperatorList`, `getTextContent`, and `RenderTask`, when the associated PDF data cannot be successfully parsed, instead of attempting to recover whatever possible of the data. The default value is `false`.
maxImageSize number <optional>
The maximum allowed image size in total pixels, i.e. width * height. Images above this value will not be rendered. Use -1 for no limit, which is also the default value.
isEvalSupported boolean <optional>
Determines if we can evaluate strings as JavaScript. Primarily used to improve performance of PDF functions. The default value is `true`.
isOffscreenCanvasSupported boolean <optional>
Determines if we can use `OffscreenCanvas` in the worker. Primarily used to improve performance of image conversion/rendering. The default value is `true` in web environments and `false` in Node.js.
isImageDecoderSupported boolean <optional>
Determines if we can use `ImageDecoder` in the worker. Primarily used to improve performance of image conversion/rendering. The default value is `true` in web environments and `false` in Node.js.
isChrome boolean <optional>
Determines if we can use bmp ImageDecoder. NOTE: Temporary option until [https://issues.chromium.org/issues/374807001] is fixed.
canvasMaxAreaInBytes number <optional>
The integer value is used to know when an image must be resized (uses `OffscreenCanvas` in the worker). If it's -1 then a possibly slow algorithm is used to guess the max value.
disableFontFace boolean <optional>
By default fonts are converted to OpenType fonts and loaded via the Font Loading API or `@font-face` rules. If disabled, fonts will be rendered using a built-in font renderer that constructs the glyphs with primitive path commands. The default value is `false` in web environments and `true` in Node.js.
fontExtraProperties boolean <optional>
Include additional properties, which are unused during rendering of PDF documents, when exporting the parsed font data from the worker-thread. This may be useful for debugging purposes (and backwards compatibility), but note that it will lead to increased memory usage. The default value is `false`.
enableXfa boolean <optional>
Render Xfa forms if any. The default value is `false`.
ownerDocument HTMLDocument <optional>
Specify an explicit document context to create elements with and to load resources, such as fonts, into. Defaults to the current document.
disableRange boolean <optional>
Disable range request loading of PDF files. When enabled, and if the server supports partial content requests, then the PDF will be fetched in chunks. The default value is `false`.
disableStream boolean <optional>
Disable streaming of PDF file data. By default PDF.js attempts to load PDF files in chunks. The default value is `false`.
disableAutoFetch boolean <optional>
Disable pre-fetching of PDF file data. When range requests are enabled PDF.js will automatically keep fetching more data even if it isn't needed to display the current page. The default value is `false`. NOTE: It is also necessary to disable streaming, see above, in order for disabling of pre-fetching to work correctly.
pdfBug boolean <optional>
Enables special hooks for debugging PDF.js (see `web/debugger.js`). The default value is `false`.
CanvasFactory Object <optional>
The factory that will be used when creating canvases. The default value is {DOMCanvasFactory}.
FilterFactory Object <optional>
The factory that will be used to create SVG filters when rendering some images on the main canvas. The default value is {DOMFilterFactory}.
enableHWA boolean <optional>
Enables hardware acceleration for rendering. The default value is `false`.
Source:

GetAnnotationsParameters

Page annotation parameters.
Type:
  • Object
Properties:
Name Type Attributes Description
intent string <optional>
Determines the annotations that are fetched, can be 'display' (viewable annotations), 'print' (printable annotations), or 'any' (all annotations). The default value is 'display'.
Source:

GetOperatorListParameters

Page getOperatorList parameters.
Type:
  • Object
Properties:
Name Type Attributes Description
intent string <optional>
Rendering intent, can be 'display', 'print', or 'any'. The default value is 'display'.
annotationMode number <optional>
Controls which annotations are included in the operatorList, for annotations with appearance-data; the values from AnnotationMode should be used. The following values are supported: - `AnnotationMode.DISABLE`, which disables all annotations. - `AnnotationMode.ENABLE`, which includes all possible annotations (thus it also depends on the `intent`-option, see above). - `AnnotationMode.ENABLE_FORMS`, which excludes annotations that contain interactive form elements (those will be rendered in the display layer). - `AnnotationMode.ENABLE_STORAGE`, which includes all possible annotations (as above) but where interactive form elements are updated with data from the AnnotationStorage-instance; useful e.g. for printing. The default value is `AnnotationMode.ENABLE`.
printAnnotationStorage PrintAnnotationStorage <optional>
isEditing boolean <optional>
Render the page in editing mode.
Source:

GetOptionalContentConfigParameters

Type:
  • Object
Properties:
Name Type Attributes Description
intent string <optional>
Determines the optional content groups that are visible by default; valid values are: - 'display' (viewable groups). - 'print' (printable groups). - 'any' (all groups). The default value is 'display'.
Source:

GetViewportParameters

Page getViewport parameters.
Type:
  • Object
Properties:
Name Type Attributes Description
scale number The desired scale of the viewport.
rotation number <optional>
The desired rotation, in degrees, of the viewport. If omitted it defaults to the page rotation.
offsetX number <optional>
The horizontal, i.e. x-axis, offset. The default value is `0`.
offsetY number <optional>
The vertical, i.e. y-axis, offset. The default value is `0`.
dontFlip boolean <optional>
If true, the y-axis will not be flipped. The default value is `false`.
Source:

MarkInfo

Properties correspond to Table 321 of the PDF 32000-1:2008 spec.
Type:
  • Object
Properties:
Name Type Description
Marked boolean
UserProperties boolean
Suspects boolean
Source:

OnProgressParameters

Type:
  • Object
Properties:
Name Type Description
loaded number Currently loaded number of bytes.
total number Total number of bytes in the PDF file.
Source:

OutlineNode

Type:
  • Object
Properties:
Name Type Description
title string
bold boolean
italic boolean
color Uint8ClampedArray The color in RGB format to use for display purposes.
dest string | Array:.<any:> | null
url string | null
unsafeUrl string | undefined
newWindow boolean | undefined
count number | undefined
items Array:.<OutlineNode:>
Source:

PDFOperatorList

PDF page operator list.
Type:
  • Object
Properties:
Name Type Description
fnArray Array:.<number:> Array containing the operator functions.
argsArray Array:.<any:> Array containing the arguments of the functions.
Source:

PDFWorkerParameters

Type:
  • Object
Properties:
Name Type Attributes Description
name string <optional>
The name of the worker.
port Worker <optional>
The `workerPort` object.
verbosity number <optional>
Controls the logging level; the constants from VerbosityLevel should be used.
Source:

RefProxy

Type:
  • Object
Properties:
Name Type Description
num number
gen number
Source:

RenderParameters

Page render parameters.
Type:
  • Object
Properties:
Name Type Attributes Description
canvasContext CanvasRenderingContext2D A 2D context of a DOM Canvas object.
viewport PageViewport Rendering viewport obtained by calling the `PDFPageProxy.getViewport` method.
intent string <optional>
Rendering intent, can be 'display', 'print', or 'any'. The default value is 'display'.
annotationMode number <optional>
Controls which annotations are rendered onto the canvas, for annotations with appearance-data; the values from AnnotationMode should be used. The following values are supported: - `AnnotationMode.DISABLE`, which disables all annotations. - `AnnotationMode.ENABLE`, which includes all possible annotations (thus it also depends on the `intent`-option, see above). - `AnnotationMode.ENABLE_FORMS`, which excludes annotations that contain interactive form elements (those will be rendered in the display layer). - `AnnotationMode.ENABLE_STORAGE`, which includes all possible annotations (as above) but where interactive form elements are updated with data from the AnnotationStorage-instance; useful e.g. for printing. The default value is `AnnotationMode.ENABLE`.
transform Array:.<any:> <optional>
Additional transform, applied just before viewport transform.
background CanvasGradient | CanvasPattern | string <optional>
Background to use for the canvas. Any valid `canvas.fillStyle` can be used: a `DOMString` parsed as CSS value, a `CanvasGradient` object (a linear or radial gradient) or a `CanvasPattern` object (a repetitive image). The default value is 'rgb(255,255,255)'. NOTE: This option may be partially, or completely, ignored when the `pageColors`-option is used.
pageColors Object <optional>
Overwrites background and foreground colors with user defined ones in order to improve readability in high contrast mode.
optionalContentConfigPromise Promise:.<OptionalContentConfig:> <optional>
A promise that should resolve with an OptionalContentConfig created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`, the configuration will be fetched automatically with the default visibility states set.
annotationCanvasMap Map:.<string:, HTMLCanvasElement:> <optional>
Map some annotation ids with canvases used to render them.
printAnnotationStorage PrintAnnotationStorage <optional>
isEditing boolean <optional>
Render the page in editing mode.
Source:

StructTreeContent

Structure tree content.
Type:
  • Object
Properties:
Name Type Description
type string either "content" for page and stream structure elements or "object" for object references.
id string unique id that will map to the text layer.
Source:

StructTreeNode

Structure tree node. The root node will have a role "Root".
Type:
  • Object
Properties:
Name Type Description
children Array:.<(StructTreeNode:|StructTreeContent:)> Array of StructTreeNode and StructTreeContent objects.
role string element's role, already mapped if a role map exists in the PDF.
Source:

TextContent

Page text content.
Type:
  • Object
Properties:
Name Type Description
items Array:.<(TextItem:|TextMarkedContent:)> Array of TextItem and TextMarkedContent objects. TextMarkedContent items are included when includeMarkedContent is true.
styles Object:.<string:, TextStyle:> TextStyle objects, indexed by font name.
lang string | null The document /Lang attribute.
Source:

TextItem

Page text content part.
Type:
  • Object
Properties:
Name Type Description
str string Text content.
dir string Text direction: 'ttb', 'ltr' or 'rtl'.
transform Array:.<any:> Transformation matrix.
width number Width in device space.
height number Height in device space.
fontName string Font name used by PDF.js for converted font.
hasEOL boolean Indicating if the text content is followed by a line-break.
Source:

TextMarkedContent

Page text marked content part.
Type:
  • Object
Properties:
Name Type Description
type string Either 'beginMarkedContent', 'beginMarkedContentProps', or 'endMarkedContent'.
id string The marked content identifier. Only used for type 'beginMarkedContentProps'.
Source:

TextStyle

Text style.
Type:
  • Object
Properties:
Name Type Description
ascent number Font ascent.
descent number Font descent.
vertical boolean Whether or not the text is in vertical mode.
fontFamily string The possible font family.
Source:

TypedArray

Type:
  • Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array
Source:

getTextContentParameters

Page getTextContent parameters.
Type:
  • Object
Properties:
Name Type Attributes Description
includeMarkedContent boolean <optional>
When true include marked content items in the items array of TextContent. The default is `false`.
disableNormalization boolean <optional>
When true the text is *not* normalized in the worker-thread. The default is `false`.
Source: