ngx-pdf-viewer-demo v2023.10.1-testworkFlow09
@kno2/ngx-pdf-viewer
Angular PDF viewer built with PDF.js.
Example Usage
Module
import { PdfViewerModule } from '@kno2/ngx-pdf-viewer';
@NgModule({
...
imports: [
BrowserModule,
PdfViewerModule
],
...
})
export class AppModule { }Template
<pdf-viewer src="path/to/pdf.pdf"></pdf-viewer>API
Inputs
src: string | Uint8Array | PDFSource, default:undefinedThe source of the PDF.
PDFSourcehas the following properties:url: stringdata?: Uint8ArrayhttpHeaders?: [key: string]: stringpassword?: string
cache: boolean, default:falseConfigures whether or not to cache documents.
zoom: number | 'page-width' | 'page-height' | 'page-fit' | 'auto', default:undefinedConfigures the default zoom. If a number is provided, should be a percentage (i.e. 10% or 200%).
paging?: 'enabled' | 'disabled' | 'hidden', default'enabled'Configures whether to disable or hide the Paging toolbar controls.
rotate?: 'enabled' | 'disabled' | 'hidden', default'enabled'Configures whether to disable or hide the Rotate toolbar controls.
remove?: 'enabled' | 'disabled' | 'hidden', default'enabled'Configures whether to disable or hide the Remove toolbar controls.
print?: 'enabled' | 'disabled' | 'hidden', default'enabled'Configures whether to disable or hide the Print toolbar controls.
download?: 'enabled' | 'disabled' | 'hidden', default'enabled'Configures whether to disable or hide the Download toolbar controls.
Outputs
pageRemove: EventEmitter<PageEvent>Emits when the Remove Page button is clicked.
PageEventhas the following property:pageNumber: number- The page number of the page that will be removed.
pageRotate: EventEmitter<PageRotationEvent>Emits when either the Rotate Clockwise of Rotate Counter-clockwise buttons are clicked.
PageRotationEventhas the following propertie:pageNumber: number- The page number of the page that will be rotated.rotation: number- The number of degrees the page that will be rotated.
Instance Methods
open(src: string | Uint8Array | PDFSource): voidOpens a PDf document using the provided
src.loadwill emit when the document has loaded.remove(event: { pageNumber: number }, emit = true): voidRemoves the page matching the provided
pageNumberfrom the viewer. Ifemitis not set tofalse, causespageRemoveto emit.rotate(event: { pageNumber: number, rotation: number }, emit = true): voidRotates the page matching the provided
pageNumberby the givenrotation.rotationvalues should be in increments of90. Ifemitis not set tofalse, causespageRotateto emit.rotateAll(rotation: number, emit = true): voidRotates the all pages by the given
rotation.rotationvalues should be in increments of90. Ifemitis not set tofalse, causespageRotateto emit for each page.reload(emit = true): voidReloads the current PDF document. If
emitis not set tofalse, causesdocumentReloadto emit.print(emit = true): voidTriggers printing of the current PDF document. If
emitis not set tofalse, causesdocumentPrintto emit.download(emit = true): voidTriggers download of the current PDF document. If
emitis not set tofalse, causesdocumentDownloadto emit.clearCache(): voidClears the document cache if it has been enabled.
Building
Run the following command to build the ngx-pdf-viewer library.
npm run build:libThe compiled build assets can be found in dist/ngx-pdf-viewer.
Development server (demo)
Run the following command to start the dev server.
npm startNavigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Running unit tests
Run the following command to execute the unit tests via Karma.
npm testRunning end-to-end tests
Run the following command to execute the end-to-end tests via Protractor.
npm run e2eDemo
To build the demo, run the following command:
npm run docsThis will compile the project and update the assets in the docs folder. This will need to be commited. GitHub will then deploy the demo automatically.