FoxitPDFSDKforWeb  7.3.0
Foxit PDF SDK for Web
PDFViewer Class Reference

Use PDFViewCtrl for the entry file. More...

Inheritance diagram for PDFViewer:
PDFUI

Public Member Functions

 close (before=this.customs.closeDocBefore, after=this.customs.closeDocAfter)
 Close the open document. More...
 
 constructor ({ preloadJR=true, preloadSR=false, libPath, jr, sr, i18n, i18nOptions, eventEmitter=new EventEmitter(), minScale=0.1, maxScale=10, defaultScale='fitWidth', scaleFrequency=4, tileSize=1200, getTileSize=null, StateHandlers=[], customs={}, keymap={}, Viewmodes=[], enableJS, enableSafeMode, stateHandlerConfig, watermarkConfig, actionOptions={}, defaultViewMode=continuousViewModeName, snapshotServer=new SnapshotServer({ uploadSnapshotAPIPath:'snapshot/upload' }), highPerformance=typeof WebAssembly==='object', annotRenderingMode={}, defaultKeyboardEventBinder=VIEWER_BINDER, defaultAnnotConfig, enableSignature=true, }={})
 Create a PDFViewer. More...
 
 createNewDoc (title="untitled.pdf", author="", pageSize={height:842, width:595}, pdfEngine=this.pdfEngine)
 Create a new pdf document. More...
 
 getAnnotManager ()
 Get annotation component manager. More...
 
 getAnnotRender (pageIndex, name)
 Get annot render. PDFPageRender::getAnnotRender. More...
 
 getCurrentPDFDoc ()
 Get current pdf doc object. More...
 
 getEnableJS ()
 Checks if PDF js can be executed. More...
 
 getEventEmitter ()
 Get event emitter. More...
 
 getPDFDocRender ()
 GetPDFDocRender. More...
 
 getPDFPageRender (index)
 GetPDFPageRender PDFDocRender::getPDFPageRender. More...
 
 getStateHandlerManager ()
 Get state handler manager. More...
 
 getViewModeManager ()
 Get view mode manager. More...
 
 init (selector)
 Initialize PDFViewer. More...
 
 killFocus ()
 Kill the focus of activated element. More...
 
 openPDFByFile (file, options={}, pdfEngine=this.pdfEngine)
 Open the local document. More...
 
 openPDFByHttpRangeRequest (request, options={fileName:''}, pdfEngine=this.pdfEngine)
 Open either a URL document by HTTP range requests or an entire file depending on if the server enables range request or not. More...
 
 redraw (force)
 Redraw the currently visible page(s). More...
 
 registerSignatureHandler (filter, subfilter, handler)
 Register a signature handler. More...
 
 reopenPDFDoc (pdfDoc, options={})
 When a document fails to open, you can call this method and reproduce the passing parameters to reopen the file that failed to open. More...
 
 setDefaultAnnotConfig (fn)
 Set the default configured callback function for the annotation.See PDFPage::addAnnot for the return object format. More...
 
 setEnableJS (enable)
 Set whether JavaScript is allowed or not. More...
 
 setJRFontMap (fontMaps)
 Set JR custom font. More...
 
 setUserName (userName, pdfEngine=this.pdfEngine)
 Set the global username. More...
 
 zoomTo (scale)
 Zoom to the given scale. More...
 

Detailed Description

Use PDFViewCtrl for the entry file.

var pdfViewer = new PDFViewCtrl.PDFViewer({
jr: {
licenseSN:'FoxitPDFSDKForWeb license SN',
licenseKey:'FoxitPDFSDKForWeb license Key'
}
})
pdfViewer.init('#pdf-viewer');

Member Function Documentation

◆ close()

PDFViewer::close (   before = this.customs.closeDocBefore,
  after = this.customs.closeDocAfter 
)
inline

Close the open document.

Parameters
{function}before - Callback before closing the document, support Promise, do not close the document when returning false. The default value is the PDFViewer initialization parameter customs.closeDocBefore.
{function}after - The callback after closing the document. The default value is the PDFViewer initialization parameter customs.closeDocAfter.
Returns
{Promise} - When before returns false, the promise returns reject

◆ constructor()

PDFViewer::constructor (   { preloadJR=true, preloadSR=false, libPath, jr, sr, i18n, i18nOptions, eventEmitter=new EventEmitter(), minScale=0.1, maxScale=10, defaultScale='fitWidth', scaleFrequency=4, tileSize=1200, getTileSize=null, StateHandlers=[], customs={}, keymap={}, Viewmodes=[], enableJS, enableSafeMode, stateHandlerConfig, watermarkConfig, actionOptions={}, defaultViewMode=continuousViewModeName, snapshotServer=new SnapshotServer({ uploadSnapshotAPIPath:'snapshot/upload' }), highPerformance=typeof WebAssembly==='object', annotRenderingMode={}, defaultKeyboardEventBinder=VIEWER_BINDER, defaultAnnotConfig, enableSignature=true, } = {})
inline

Create a PDFViewer.

Parameters
options{object} - The configuration required to create the PDFViewer.
options.jr{object} - JR engine config.
options.jr.licenseKey{string} - String of licenseKey information.
options.jr.licenseSN{string} - String of licenseSN information.
options.jr.l{string} - String of license information. If he is assigned a value, neither jr.licenseKey nor jr.licenseSN is valid
[options.jr.workerPath=options.libPath]{string} - The JR engine worker path.
If it's a relative path, it's relative to "options.libPath".
If it's url, it's url.
[options.jr.enginePath=options.libPath+'jr-engine']{string} - The JR engine path.
If it's a relative path, it's relative to "options.libPath".
If it's url, it's url.
[options.jr.fontPath='../external/brotli']{string} - The JR engine render fonts path. If it's a relative path, it's relative to "options.libPath".
If it's url, it's url. If you don't want the font resources under external/brotil, you can use the fonts on our server by configuring http://webpdf.foxitsoftware.com/webfonts
[options.jr.readBlock=8192]{number} Size of each read block. default 8192 = 8 *1024 = 8KB
[options.jr.brotli]{object} - brotli config
[options.jr.brotli.core]{boolean} - This parameter is used to set whether to use brotli compression or not. This is specially useful on a legacy browser but with high-speed network. True is the default value which means to enable the brotli loading.
[options.preloadJR=true]{boolean} - Proload JR engine.
[options.libPath]{string} - The PDFViewer lib package path. The default is the current page path.
[options.minScale=0.1]{number} - Minimum magnification
[options.maxScale=10]{number} - Maximum magnification
[options.defaultScale='fitWidth']{number|string} - Multiple of the default display. string enum: fitWidth, fitHeight
[options.scaleFrequency=4]{number} - Set integers greater than or equal to 0. It will affect page rendering.
The default value is 4, then 1/4=0.25, such as 1.1 times, is 1.25 times the size of the picture to reduce drawing overhead.
The larger the value, the clearer it is, but the higher the performance penalty. If the value is set to 0, it is rendered in raw multiples, not scaled. The biggest performance penalty.
[options.tileSize=1200]{number} - Size of tile display. The unit pixel.
When the display area is larger than tileSize, it will be cut into tiles for display.
The recommended range is 500-3000. The more blocks cut, the less efficient the display.
[options.getTileSize=null]{Function} - Get tile size when renderring page.
[options.annotRenderingMode]{object} - Defines the rendering mode of each annotation type, currently supports 'native' and 'canvas'.
[options.annotRenderingMode.highlight='canvas']{string} - rendering mode of area-highlight and text-highlight, it supports 'native' and 'canvas'.
[options.annotRenderingMode.pushButton='native']{string} - rendering mode of push button, it supports 'native' and 'canvas'.
[options.annotRenderingMode.textField='native']{string} - rendering mode of text field, it supports 'native' and 'canvas'.
[options.annotRenderingMode.freetext='canvas']{string} - rendering mode of freetext, it supports 'native' and 'canvas'.
[options.i18n]{i18next} - i18next instance https://www.i18next.com/
[options.i18nOptions]{object} - If options.i18n does not exist, options.i18n is generated through the options.i18nOptions configuration
[options.i18nOptions.initOption={ns:'viewer_'}]{object} - Multilingual config. https://www.i18next.com/overview/configuration-options
[options.i18nOptions.path=options.libPath+'locales']{string} - Multilingual path.
If it's a relative path, it's relative to options.lib.
If it's url, it's url.
[options.eventEmitter]{EventEmitter} - default: new EventEmitter(); eventemitter3 https://github.com/primus/eventemitter3
[options.Viewmodes=[]]{IViewMode[]} - View mode compontent.
[options.defaultViewMode='continuous-view-mode']{string} - Default is continuous view mode.
[options.defaultAnnotConfig=function(type,intent){}]{Function} - Gets the default configured callback for the annotation.See PDFPage::addAnnot for the return object format.
[options.customs]{object} - Custom component.
[options.customs.closeDocBefore=function(){}]{Function} - Callback before closing the document, support Promise, do not close the document when returning false.
[options.customs.closeDocAfter=function(){}]{Function} - Callback after closing the document, support Promise.
[options.customs.getDocPermissions=function(doc){return-1}]{Function} - Get user access permissions. -1 represents all permissions.
[options.customs.getAdditionalPerm=function(doc){return-1}]{Function} - Get additional permissions. Please refer to Additional_Permission.
[options.customs.ScrollWrap=ScrollWrap]{ScrollWrap} - The component that controls the roll.
[options.customs.PDFViewerRendering]{PDFViewerRendering} - Called when the viewer rendering.
[options.customs.PDFDocRendering]{PDFDocRendering} - Called when the doc rendering.
[options.customs.PDFPageRendering]{PDFPageRendering} - Called when the page rendering.
[options.StateHandlers=[]]{IStateHandler[]} - pdf viewer state handler.
property i18n
{i18next} - i18next instance
property customs
{object} - Custom component.
property config
{object} - { jr: options.jr, licenseKey: options.licenseKey, licenseSN: options.licenseSN, minScale: options.minScale, maxScale: options.maxScale, defaultViewMode: options.defaultViewMode, }
property eventEmitter
{EventEmitter} - pdfViewer EventEmitter
eventemitter3 https://github.com/primus/eventemitter3

◆ createNewDoc()

PDFViewer::createNewDoc (   title = "untitled.pdf",
  author = "",
  pageSize = {height:842, width:595},
  pdfEngine = this.pdfEngine 
)
inline

Create a new pdf document.

Parameters
title{*} - {string} New pdf title, default value is "untitled.pdf".
author{*} - {string} New Pdf author.
pageSize{*} - {object} {height:842, width:595}.
Returns
{Promise.<PDFDoc>} - PDF document object

◆ getAnnotManager()

PDFViewer::getAnnotManager ( )
inline

Get annotation component manager.

Returns
{ViewerAnnotManager}

◆ getAnnotRender()

PDFViewer::getAnnotRender (   pageIndex,
  name 
)
inline

Get annot render. PDFPageRender::getAnnotRender.

Parameters
pageIndex{number} - page index
name{string} - annotation name
Returns
{AnnotRender | null} - Returns null if the annotation has‘t been rendered.

◆ getCurrentPDFDoc()

PDFViewer::getCurrentPDFDoc ( )
inline

Get current pdf doc object.

Returns
{PDFDoc | null} Null is returned when the document is not currently open

◆ getEnableJS()

PDFViewer::getEnableJS ( )
inline

Checks if PDF js can be executed.

Returns
{true | false} True allows JavaScript to execute, and false does the opposite

◆ getEventEmitter()

PDFViewer::getEventEmitter ( )
inline

Get event emitter.

Returns
{EventEmitter}

◆ getPDFDocRender()

PDFViewer::getPDFDocRender ( )
inline

GetPDFDocRender.

Returns
{PDFDocRender | null} Returns null when not found.

◆ getPDFPageRender()

PDFViewer::getPDFPageRender (   index)
inline

GetPDFPageRender PDFDocRender::getPDFPageRender.

Parameters
index{number} page index
Returns
{PDFPageRender | null} Returns null when not found.

◆ getStateHandlerManager()

PDFViewer::getStateHandlerManager ( )
inline

Get state handler manager.

Returns
{StateHandlerManager}

◆ getViewModeManager()

PDFViewer::getViewModeManager ( )
inline

Get view mode manager.

Returns
{ViewModeManager} - Instance of ViewModeManager

◆ init()

PDFViewer::init (   selector)
inline

Initialize PDFViewer.

Parameters
{string|HTMLElement}selector - Jquery selector. PDFViewer dom host.

◆ killFocus()

PDFViewer::killFocus ( )
inline

Kill the focus of activated element.

Since
7.3.0
Returns
{Promise<boolean>} - True for success.

◆ openPDFByFile()

PDFViewer::openPDFByFile (   file,
  options = {},
  pdfEngine = this.pdfEngine 
)
inline

Open the local document.

Parameters
file{File|Blob|ArrayBuffer|TypeArray|ViewData} - File stream of PDF document.
type advantage disadvantage
File balance memory and speed. /
Blob balance memory and speed /
ArrayBuffer fast large memory usage
options={fileName:''}{object}
[options.password]{string} - document password
[options.encryptPassword]{string} - The document's password is encrypted again. You can refer to the logic of path 'server/encrypt-password' to get your encryptPassword
[options.fileName='']{string} - document filename
[options.readBlock]{number} Size of each read block. default equals options.jr.readBlock.
[options.annotsJson]{object} - Json format data for the initial annotation
[options.fdf]{object} - FDF file containing the initial annotation data.
[options.fdf.file]{File|Blob|ArrayBuffer|TypeArray|ViewData} - Specify fdf file's stream for the initial annotation.
[options.fdf.type]{number} - Specify data type which will be imported: 1 for form data, 2 for annotations.
[options.drm]{object} When this value is set, the DRM decryption process is invoked.
[options.drm.isEncryptMetadata]{boolean} A boolean value to decide whether to encrypt metadata or not. true means to encrypt metadata, and false means not to encrypt metadata.
[options.drm.subFilter]{string} The sub filter of PDF document.
[options.drm.cipher]{number} Cipher type. Please refer to values starting from Cipher_Type::cipherRC4 and this should be one of these values except Cipher_Type.cipherNone.
[options.drm.keyLength]{number} The key length, in bytes.
For Cipher_Type::cipherRC4 cipher, this value should be between 5 and 16.
For Cipher_Type::cipherAES cipher, this value should be 16 or 32.
[options.drm.isOwner]{boolean} A boolean value to decide whether current user is owner or not. true means current user is owner, and false means current user is not owner.
[options.drm.userPermissions]{number} The user permissions. Please refer to values starting from User_Permissions::print and this can be one or combination of these values.
[options.drm.fileId]{string} The file identity string.
[options.drm.initialKey]{string} The user specified initial key for encryption.
[options.fileOpen]{object} When this value is set, the fileOpen decryption process is invoked.
[options.fileOpen.encryptKey]{array} Decrypt an array of charcodes for the key
[options.jwt]{function} Must be filled when JWT calibration is enabled.
Returns
{Promise.<PDFDoc>} - this is promise. reject: {error:number, pdfDoc: pdfDoc, encryptDict: object}
error=3 wrong password error=11 security handler error

◆ openPDFByHttpRangeRequest()

PDFViewer::openPDFByHttpRangeRequest (   request,
  options = {fileName:''},
  pdfEngine = this.pdfEngine 
)
inline

Open either a URL document by HTTP range requests or an entire file depending on if the server enables range request or not.

Parameters
request{object}
request.range{object} HTTP range requests, responseType = 'arraybuffer'
request.range.url{string} Request the url of the file. The second parameter to XMLHttpRequest.open, default request.range.url, this URL is relative to the path of your HTML page.
[request.range.type='GET']{number} The first parameter to XMLHttpRequest.open, default GET
[request.range.user]{number} The fourth parameter to XMLHttpRequest.open
[request.range.password]{number} The fifth parameter to XMLHttpRequest.open
[request.range.headers]{object} Set the request header for XMLHttpRequest. eg: XMLHttpRequest.setRequestHeader(x, request.header.headers.x)
[request.range.chunkSize=131072]{number} Size of each Range sharding request. default 131072 = 128 *1024 = 128KB
[request.range.extendOptions]{string} Set the response header to get additional options
[request.size]{number} the size of the document
options={fileName:''}{object}
[options.password]{string} - document password
[options.encryptPassword]{string} - The document's password is encrypted again. You can refer to the logic of path 'server/encrypt-password' to get your encryptPassword
[options.fileName='']{string} - document filename
[options.readBlock]{number} Size of each read block. default equals options.jr.readBlock.
[options.annotJson]{object} - Json format data for the initial annotation
[options.fdf]{object} - FDF file containing the initial annotation data.
[options.fdf.file]{File|Blob|ArrayBuffer|TypeArray|ViewData} - Specify fdf file's stream for the initial annotation.
[options.fdf.type]{number} - Specify data type which will be imported: 1 for form data, 2 for annotations.
[options.drm]{object} When this value is set, the DRM decryption process is invoked.
[options.drm.isEncryptMetadata]{boolean} A boolean value to decide whether to encrypt metadata or not. true means to encrypt metadata, and false means not to encrypt metadata.
[options.drm.subFilter]{string} The sub filter of PDF document.
[options.drm.cipher]{number} Cipher type. Please refer to values starting from Cipher_Type::cipherRC4 and this should be one of these values except Cipher_Type.cipherNone.
[options.drm.keyLength]{number} The key length, in bytes.
For Cipher_Type::cipherRC4 cipher, this value should be between 5 and 16.
For Cipher_Type::cipherAES cipher, this value should be 16 or 32.
[options.drm.isOwner]{boolean} A boolean value to decide whether current user is owner or not. true means current user is owner, and false means current user is not owner.
[options.drm.userPermissions]{number} The user permissions. Please refer to values starting from User_Permissions::print and this can be one or combination of these values.
[options.drm.fileId]{string} The file identity string.
[options.drm.initialKey]{string} The user specified initial key for encryption.
[options.fileOpen]{object} When this value is set, the fileOpen decryption process is invoked.
[options.fileOpen.encryptKey]{Array<number>} Decrypt an array of charcodes for the key
[options.jwt]{function} Must be filled when JWT calibration is enabled.
Returns
{Promise<PDFDoc>} - this is promise. reject: {error:number, pdfDoc: pdfDoc, encryptDict: object}
error=3 wrong password error=11 security handler error
function example (pdfViewer) {
pdfViewer.openPDFByHttpRangeRequest({
range: {
url: 'http://10.103.4.154:9898/_testfile/big/performance-diffSize/Test_1GB.pdf',
chunkSize: 10 * 1024 * 1024
}
});
}
function example (pdfViewer) {
// response header include:
// Fv-Extend-Open-Header: eyJwYXNzd29yZCI6Im93bmVyIn0=
// 'eyJwYXNzd29yZCI6Im93bmVyIn0=' equals btoa(JSON.stringify({password:'owner'}))
// So the target options value is {fileName: 'fileName.pdf', password: 'owner'}
// To get the target options
// Object.assign({},JSON.parse(atob(xmlHttp.getResponseHeader(range.extendOptions)),options}
pdfViewer.openPDFByHttpRangeRequest({
range: {
url: 'http://10.103.4.154:9898/_testfile/big/performance-diffSize/Test_1GB.pdf',
extendOptions: 'Fv-Extend-Open-Header'
}
}, {fileName: 'fileName.pdf'});
}

◆ redraw()

PDFViewer::redraw (   force)
inline

Redraw the currently visible page(s).

Parameters
[force=false]- {booleam} true: This will also refresh the cache.
Returns
{Promise}

◆ registerSignatureHandler()

PDFViewer::registerSignatureHandler (   filter,
  subfilter,
  handler 
)
inline

Register a signature handler.

Parameters
filter{string} - Filter of signature handler.
subfilter{string} - Subfilter of signature handler.
handler{object} - An object specify http api to sign and verify signatures.
[handler.sign]{string} - An object specify server api to sign and verify signatures.
[handler.verify]{string} - An object specify server api to sign and verify signatures.
Returns
{Promise<*>} - null.
Since
7.3.0

◆ reopenPDFDoc()

PDFViewer::reopenPDFDoc (   pdfDoc,
  options = {} 
)
inline

When a document fails to open, you can call this method and reproduce the passing parameters to reopen the file that failed to open.

Parameters
pdfDoc- {PDFDoc}
options- {object}
options={fileName:''}{object}
[options.password]{string} - document password
[options.encryptPassword]{string} - The document's password is encrypted again. You can refer to the logic of path 'server/encrypt-password' to get your encryptPassword
[options.fileName='']{string} - document filename
[options.annotJson]{object} - Json format data for the initial annotation
[options.fdf]{object} - Json format data for the initial annotation
[options.fdf.file]{File|Blob|ArrayBuffer|TypeArray|ViewData} - Specify fdf file's stream for the initial annotation.
[options.fdf.type]{number} - Specify data type which will be imported: 1 for form data, 2 for annotations.
[options.jwt]{function} Must be filled when JWT calibration is enabled.
[options.drm]{object} When this value is set, the DRM decryption process is invoked.
[options.drm.isEncryptMetadata]{boolean} A boolean value to decide whether to encrypt metadata or not. true means to encrypt metadata, and false means not to encrypt metadata.
[options.drm.subFilter]{string} The sub filter of PDF document.
[options.drm.cipher]{number} Cipher type. Please refer to values starting from Cipher_Type.cipherRC4 and this should be one of these values except Cipher_Type::cipherNone.
[options.drm.keyLength]{number} The key length, in bytes.
For SecurityConstsPDF::cipherRC4 cipher, this value should be between 5 and 16.
For SecurityConstsPDF::cipherAES cipher, this value should be 16 or 32.
[options.drm.isOwner]{boolean} A boolean value to decide whether current user is owner or not. true means current user is owner, and false means current user is not owner.
[options.drm.userPermissions]{number} The user permissions. Please refer to values starting from User_Permissions::print and this can be one or combination of these values.
[options.drm.fileId]{string} The file identity string.
[options.drm.initialKey]{string} The user specified initial key for encryption.
[options.fileOpen]{object} When this value is set, the fileOpen decryption process is invoked.
[options.fileOpen.encryptKey]{number[]} Decrypt an array of charcodes for the key
Returns
{Promise<PDFDoc>} reject: {error:number, pdfDoc: pdfDoc, encryptDict: object}
error=3 wrong password error=11 security handler error

◆ setDefaultAnnotConfig()

PDFViewer::setDefaultAnnotConfig (   fn)
inline

Set the default configured callback function for the annotation.See PDFPage::addAnnot for the return object format.

Parameters
fn{Function} - The default configured callback function.

◆ setEnableJS()

PDFViewer::setEnableJS (   enable)
inline

Set whether JavaScript is allowed or not.

Parameters
enable{boolean} True allows JavaScript to execute, and false does the opposite

◆ setJRFontMap()

PDFViewer::setJRFontMap (   fontMaps)
inline

Set JR custom font.

Parameters
fontMaps{Array<FontMap>} - Custom fonts. The Settings are valid before opening the document.
Since
7.2.0
function example (pdfViewer) {
pdfViewer.setJRFontMap([{
nameMatches: [
// A string or regular expression that matches a literal name. Can be an empty array or unset.
/(helvetica)|(helveticabold)|(helveticaoblique)/,
],
glyphs: [
{
bold: 0x1f0, // 0b111110000 match 500,600,700,800,900 weight font
flags: 0x80000, // Font Descriptor Flags
url: 'NotoSans-Bold.ttf.brotli',
isBrotli: true,
},
{
bold: -1, // Matches any word width
flags: 0x80000,
url: 'NotoSans-Regular.ttf'
},
]
}])
}

◆ setUserName()

PDFViewer::setUserName (   userName,
  pdfEngine = this.pdfEngine 
)
inline

Set the global username.

Parameters
userName{string} Set the global username that will be used for the annotation title
Returns
{Promise.<void>}

◆ zoomTo()

PDFViewer::zoomTo (   scale)
inline

Zoom to the given scale.

Parameters
{number|string}scale - Greater than zero.
If it's a string, only 'fitWidth' and 'fitHeight' are valid.
Returns
{Promise}

Foxit Software Corporation Logo
@2019 Foxit Software Incorporated. All rights reserved.