This is a plugin for the AlfDocumentPreview widget that provides the ability to render PDF documents using the Mozilla pdf.js project (https://github.com/mozilla/pdf.js).
The code was adapted from a YUI2 based code that was originally a Share Extras (http://share-extras.github.io/) project and was then integrated into Alfresco Share for version 5.0. It has since be updated to remove the YUI2 dependencies and work independently of Alfresco Share.
- Copyright:
- Copyright (C) 2005-2020 Alfresco Software Limited
- License:
- GNU Lesser General Public License, see: Open Source Licensing
- Source:
Mixes In
Members
-
_findController :object
-
The first time that the onToggleSearchBar function is called this will be instantiated with a new instance of a module:alfresco/preview/PdfJs/PDFFindController that can then be used to search the document.
Type:
- object
- Default Value:
- null
- Source:
-
_findPrevious :boolean
-
Indicates whether or not to search backwards through the PDF when finding the next hit that matches the current query.
Type:
- boolean
- Default Value:
- false
- Source:
-
_highlightAll :boolean
-
Indicates whether or not all search hits should be highlighted when searching.
Type:
- boolean
- Default Value:
- false
- Source:
-
_matchCase :boolean
-
Indicates whether or not case should be matched when searching the PDF.
Type:
- boolean
- Default Value:
- false
- Source:
-
_query :string
-
The query to use for searching within the PDF text.
Type:
- string
- Default Value:
- null
- Source:
-
cssRequirements :object[]
-
An array of the CSS files to use with this widget.
Type:
- object[]
- Default Value:
- [{cssFile:"./css/PdfJs.css"}]
- Source:
-
currentScaleSelection :string
-
Current scale selection from the drop-down scale menu
Type:
- string
- Default Value:
- null
- Source:
-
documentConfig :object
-
Stored configuration for this particular document, including page number and zoom level. Persisted to local browser storage.
Type:
- object
- Default Value:
- {}
- Source:
-
i18nRequirements :object[]
-
An array of the i18n files to use with this widget.
Type:
- object[]
- Default Value:
- [{i18nFile: "./i18n/PdfJs.properties"}]
- Source:
-
inDashlet :boolean
-
Whether the previewer is embedded in a dashlet
Type:
- boolean
- Default Value:
- false
- Source:
-
maximized :boolean
-
Whether the page view is maximised within the client
Type:
- boolean
- Default Value:
- false
- Source:
-
nonAmdDependencies :String[]
-
Declares the dependencies on PdfJs dependencies.
Type:
- String[]
- Source:
-
numPages :int
-
Total number of pages in the current document
Type:
- int
- Default Value:
- 0
- Source:
-
pageNum :int
-
Current page number
Type:
- int
- Default Value:
- 1
- Source:
-
pages :array
-
Cached pages from the PDF doc
Type:
- array
- Default Value:
- []
- Source:
-
pageText :array
-
Cached page text from the document, for searching purposes
Type:
- array
- Default Value:
- []
- Source:
-
pdfDocument :object
-
Cached PDF document, once loaded from the server
Type:
- object
- Default Value:
- null
- Source:
-
widgets :object
-
Type:
- object
- Default Value:
- {}
- Source:
-
widgetsForControls :array
-
The widget model for building the plugin controls.
Type:
- array
- Source:
-
workerSrc :string
-
Store the pdf.js url for use with PDFJS.workerSrc (4.2 Specific).
Type:
- string
- Default Value:
- empty string
- Source:
-
<inner> attributes :object
-
Configuration attributes
Type:
- object
- Source:
Properties:
Name Type Description attributes
Methods
-
_browserSupportsHtml5Storage() → {boolean}
-
Check if the web browser supports local storage
- Source:
Returns:
true if local storage is available, false otherwise- Type
- boolean
-
_isCanvasSupported()
-
Sniff test to determine if the browser supports the canvas element
Based on http://stackoverflow.com/questions/2745432/best-way-to-detect-that-html5-canvas-is-not-supported
- Source:
-
_loadDocumentConfig()
-
Load configuration for the current document
- Source:
-
_loadPdf()
-
Fetch the PDF content and display it
- Source:
-
_navigateTo(dest)
-
Navigate the viewer to the specified document outline item
Parameters:
Name Type Description dest
object outline object item, from the document outline - Source:
-
_onGetDocumentFailure()
-
TODO: Need to handle failures (e.g. replace YUI/Share code calls) Error encountered retrieving PDF document
- Source:
Fires:
-
_onGetDocumentSuccess()
-
PDF document retieved successfully
- Source:
-
_passwordReload(password)
-
Function to reload the pdf with a password supplied
Parameters:
Name Type Description password
string - Source:
-
_renderPdf()
-
Display the PDF content in the container
- Source:
-
_scrollToPage(n)
-
Scrolls the displayed PDF to the specified page.
Parameters:
Name Type Description n
int Number of the page to scroll to, must be 1 or greater. - Source:
-
_searchReset()
-
This function resets the highlights by searching for nothing
- Source:
-
_updatePageControls()
-
Updates the paging controls shown in the toolbar by publishing the page number information so that the "set page" menu item label can be updated (e.g. to show "1 / 20", etc) and publishing on topics to enable or disable the previous and next page menu items depending upon whether or not the first or last page of the PDF is being viewed.
- Source:
-
_updateZoomControls()
-
Update the zoom controls shown in the toolbar by publishing on topics to enable and disable the zoom in an out menu items as the limits of zoom scale are reached as well as publishing on a topic to update the label of "set zoom level" menu item to show the current scale (as a percentage).
- Source:
-
display()
-
Display the node.
- Source:
-
onDownloadClick()
-
Download Original document menu link click handler
- Source:
-
onDownloadPDFClick()
-
Download PDF click handler (for thumbnailed content only)
- Source:
-
onFindChange()
-
Text value changed in Find text input field
- Source:
-
onFindChangeHighlight(payload)
-
Parameters:
Name Type Description payload
object The payload indicating whether or not to highlight all search hits - Source:
-
onFindChangeMatchCase(payload)
-
Parameters:
Name Type Description payload
object The payload indicating whether or not to match case on search - Source:
-
onFindNext(payload)
-
Parameters:
Name Type Description payload
object - Source:
-
onFindPrevious(payload)
-
Parameters:
Name Type Description payload
object - Source:
-
onFindQuery(payload)
-
Parameters:
Name Type Description payload
object The payload indicating whether or not to match case on search - Source:
-
onInterfaceToggle()
-
Function to toggle interface elements
- Source:
-
onLinkClick(payload)
-
This function is called whenever the link control bar is displayed or hidden and calls onRecalculatePreviewLayout to re-render the main PDF display and then calls [onLinkUpdateRequest] module:alfresco/preview/PdfJs/PdfJs#onLinkUpdateRequest to ensure that the displayed link reflects the currently selected page.
Parameters:
Name Type Description payload
object The payload from the show/hide link controls toggle. - Source:
-
onLinkUpdateRequest()
-
This function handles requests to update the link URL value to reflect the currently selected page in the PDF.
- Source:
-
onMaximizeClick(payload)
-
Called on selection of either full screen or full window modes. This function does not actually handle the full screen or full window capability (this is achieved by placing the main AlfDocumentPreview widget into a FullScreenWidgets widget). Instead this simply handles the associated document resizing for the new container.
Parameters:
Name Type Description payload
object Indicates whether or not maximize has been enabled or disabled. - Source:
-
onNotificationToggle(payload)
-
Function to display and or toggle a notification element
Parameters:
Name Type Description payload
object - Source:
-
onPageNext()
-
Next button or key clicked
- Source:
-
onPagePrevious()
-
Previous page button or key clicked
- Source:
-
onRecalculatePreviewLayout()
-
Handler for window resize event
- Source:
-
onSetPageConfirmation(payload)
-
This will be called when the user has selected the page that they wish to jump to.
Parameters:
Name Type Description payload
object The payload containing the details of the page to skip to. - Source:
Fires:
-
onSetPageRequest(payload)
-
This function is called when the user clicks on the set page menu item. It will display a dialog containing a form control that allows the page number to be set. Only valid page numbers can be entered.
Parameters:
Name Type Description payload
object The payload from the menu item click. - Source:
-
onThumbnailClicked()
-
This function is called whenever an individual thumbnail in the sidebar is clicked. It will automatically navigate the user to the page in the PDF represented by that thumbnail image.
- Source:
-
onToggleSearchBar()
-
Handles requests to show and hide the search tools bar. The first time this is called requesting that the search tools be displayed, _findController will be instantiated with a new [PDFFindController]PDFFindController.
- Source:
-
onViewerLoaded()
-
Handler for successful load of the viewer markup webscript
- Source:
-
onViewerScroll(payload)
-
Handles publications from the associated DocumentView indicating that the viewer has been scrolled so that the page number and active page can be updated.
Parameters:
Name Type Description payload
object This is expected to be an empty object. - Source:
-
onWindowHashChange()
-
Handler for window hashchange event See http://caniuse.com/#search=hash
- Source:
-
onWindowUnload()
-
Window unload event handler to save document configuration to local storage
- Source:
-
onZoomChange(payload)
-
Zoom level changed via the zoom menu button
Parameters:
Name Type Description payload
object The payload containing the details of the new zoom level - Source:
-
onZoomIn(payload)
-
Zoom in menu item clicked. This will calculate a new zoom scale which will then be applied to the DocumentView.
Parameters:
Name Type Description payload
object The payload from the zoom in menu item - Source:
-
onZoomOut(payload)
-
Zoom out menu item clicked. This will calculate a new zoom scale which will then be applied to the DocumentView.
Parameters:
Name Type Description payload
object The payload from the zoom out menu item - Source:
-
removeSpinner()
-
Removes the Spinner indicating that the PDF document is being loaded. Also removes the subscription created to listen for the PDF loading event (as this should only occur once).
- Source:
-
renderPageContainer(pagesRefMap, promisedPages)
-
Parameters:
Name Type Description pagesRefMap
object promisedPages
array - Source:
-
renderThumbnails(widgets)
-
Callback when the tab container is created. This will render the initial view of thumbnails.
Parameters:
Name Type Description widgets
array The array of widgets that were created when processing the sidebar - Source:
-
report() → {String}
-
Tests if the plugin can be used in the users browser.
- Source:
Returns:
Returns nothing if the plugin may be used, otherwise returns a message containing the reason it cant be used as a string.- Type
- String
-
setHeight()
-
Set the height of the viewer area where content is displayed, so that it occupies the height of the parent previewer element minus the menu bar.
- Source: