Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GcPdfViewer

GcDocs PDF Viewer control.

Hierarchy

  • ReportViewer
    • GcPdfViewer

Implements

  • IViewerHost

Index

Constructors

constructor

  • GcDocs PDF Viewer constructor.

    Parameters

    • element: HTMLElement | string

      root container element or selector pattern used to select the root container element.

    • Default value options: Partial<ViewerOptions> = {}

      Viewer options. @see ViewerOptions for further information.

    Returns GcPdfViewer

Accessors

annotations

  • get annotations(): Promise<{ annotations: AnnotationBase[]; pageIndex: number }[]>
  • Gets all document annotations.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.addDefaultPanels();
    viewer.onAfterOpen.register(function() {
      viewer.annotations.then(function(data) {
        for(var i = 0; i < data.length; i++){
          var pageAnnotationsData = data[i];
          var pageIndex = pageAnnotationsData.pageIndex;
          var annotations = pageAnnotationsData.annotations;
          console.log("Page with index " + pageIndex + " contains " + annotations.length + " annotation(s)");
        }
      });
    });
    viewer.open('Test.pdf');
    

    Returns Promise<{ annotations: AnnotationBase[]; pageIndex: number }[]>

beforeUnloadConfirmation

  • get beforeUnloadConfirmation(): boolean
  • set beforeUnloadConfirmation(enable: boolean): void
  • Ask the user if he want to leave the page when document is modified.

    example
     var viewer = new GcPdfViewer('#root', { supportApi: 'api/pdf-viewer' } );
     viewer.addDefaultPanels();
     viewer.addAnnotationEditorPanel();
     viewer.addFormEditorPanel();
     viewer.beforeUnloadConfirmation = true;
     

    Returns boolean

  • Ask the user if he want to leave the page when document is modified.

    example
     var viewer = new GcPdfViewer('#root', { supportApi: 'api/pdf-viewer' } );
     viewer.addDefaultPanels();
     viewer.addAnnotationEditorPanel();
     viewer.addFormEditorPanel();
     viewer.beforeUnloadConfirmation = true;
     

    Parameters

    • enable: boolean

    Returns void

canEditDocument

  • get canEditDocument(): boolean
  • Indicates whether opened document can be edited using SupportApi.

    example
    if(viewer.canEditDocument) {
      alert("Document editing features enabled.");
    } else {
      alert("Document editing features disabled.");
    }
    

    Returns boolean

currentUserName

  • get currentUserName(): string
  • set currentUserName(userName: string): void
  • Gets/sets the current user name. The property is used by Annotation Editor as default value for 'author' field.

    example
    viewer.currentUserName = "John";
    
    example
    alert("The current user name is " + viewer.currentUserName);
    

    Returns string

  • Gets/sets the current user name. The property is used by Annotation Editor as default value for 'author' field.

    example
    viewer.currentUserName = "John";
    
    example
    alert("The current user name is " + viewer.currentUserName);
    

    Parameters

    • userName: string

    Returns void

editMode

  • get editMode(): EditMode
  • set editMode(mode: EditMode): void
  • Gets or sets more precise Edit mode for Annotations or Form editor.

    example
     // Set the layout mode to "Annotation editor"
     viewer.layoutMode = 1;
     // Set the edit mode to "Square".
     viewer.editMode = 4;
     

    Returns EditMode

  • Gets or sets more precise Edit mode for Annotations or Form editor.

    example
     // Set the layout mode to "Annotation editor"
     viewer.layoutMode = 1;
     // Set the edit mode to "Square".
     viewer.editMode = 4;
     

    Parameters

    • mode: EditMode

    Returns void

fileData

  • get fileData(): Uint8Array | null
  • Gets the file data. Available when keepFileData option is set to true.

    example
    var viewer = new GcPdfViewer('#root', { keepFileData: true });
    viewer.open('Test.pdf');
    viewer.onAfterOpen.register(function() {
      var pdfFileData = viewer.fileData;
    });
    

    Returns Uint8Array | null

fileName

  • get fileName(): string
  • Gets the file name that was used to open the document. The file name is determined as follows:

    • if a local file was opened using the "Open File" dialog, returns the local file name;
    • else, if a new file was created using the "newDocument" method, returns the argument passed to that method;
    • else, if options.friendlyFileName is not empty, returns its value;
    • else, returns the name generated from the URL passed to the "open" method.
    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      alert("The document is opened, the fileName is " + viewer.fileName);
    });
    viewer.open('MyDocuments/Test.pdf');
    

    Returns string

fileUrl

  • get fileUrl(): string
  • Gets the URL that was used to open the document. Returns an empty string when the document was opened from binary data.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      alert("The document is opened, the fileUrl is " + viewer.fileUrl);
    });
    viewer.open('MyDocuments/Test.pdf');
    

    Returns string

fingerprint

  • get fingerprint(): string
  • An unique document identifier.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      alert("The document opened, an unique document identifier is "+ viewer.fingerprint);
    });
    viewer.open('Test.pdf');
    

    Returns string

hasChanges

  • get hasChanges(): boolean
  • Returns true if the document has been modified by the user.

    example
    if(viewer.hasChanges) {
      alert("The document has been changed.");
    }
    

    Returns boolean

hasCopyData

  • get hasCopyData(): boolean
  • Indicates if buffer contains any data.

    example
    if(viewer.hasCopyData) {
      viewer.execPasteAction();
    }
    

    Returns boolean

hasDocument

  • get hasDocument(): boolean
  • Indicates whether document is loaded into view.

    example
    if(!viewer.hasDocument) {
      viewer.open("sample.pdf");
    }
    

    Returns boolean

hasRedoChanges

  • get hasRedoChanges(): boolean
  • Gets a value indicating whether the pdf viewer can redo document changes.

    example
    if(viewer.hasRedoChanges) {
      viewer.redoChanges();
    }
    

    Returns boolean

hasReplyTool

  • get hasReplyTool(): boolean
  • Indicates whether the Reply Tool has been added.

    example
    var viewer = new GcPdfViewer('#root');
    if(viewer.hasReplyTool) {
      alert("The Reply Tool has not been added to the viewer.");
    } else {
      alert("The Reply Tool has been added to the viewer.");
    }
    viewer.open('Test.pdf');
    

    Returns boolean

hasUndoChanges

  • get hasUndoChanges(): boolean
  • Gets a value indicating whether the pdf viewer can undo document changes.

    example
    if(viewer.hasUndoChanges) {
      viewer.undoChanges();
    }
    

    Returns boolean

hideAnnotations

  • get hideAnnotations(): boolean
  • set hideAnnotations(hide: boolean): void
  • Gets if annotations layer is hidden.

    example
    // Hide annotations:
    viewer.hideAnnotations = true;
    

    Returns boolean

  • Sets if annotations layer should be hidden.

    example
    // Hide annotations:
    viewer.hideAnnotations = true;
    

    Parameters

    • hide: boolean

    Returns void

isUpdating

  • get isUpdating(): boolean
  • Returns true if notifications suspended by calls to @see:beginUpdate.

    example

    var isUpdatingFlag = viewer.isUpdating;

    Returns boolean

layoutMode

  • Gets or sets the layout mode (0 - Viewer, 1 - AnnotationEditor or 2 - FormEditor).

    default

    0

    example
     // Set the layout mode to "Form editor"
     viewer.layoutMode = 2;
     

    Returns LayoutMode

  • Gets or sets the layout mode (0 - Viewer, 1 - AnnotationEditor or 2 - FormEditor).

    default

    0

    example
     // Set the layout mode to "Form editor"
     viewer.layoutMode = 2;
     

    Parameters

    Returns void

onAfterOpen

  • get onAfterOpen(): EventFan<AfterOpenEventArgs>
  • Occurs when a document is opened.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      alert("The document opened.");
    });
    viewer.open('Test.pdf');
    

    Returns EventFan<AfterOpenEventArgs>

onBeforeOpen

  • get onBeforeOpen(): EventFan<BeforeOpenEventArgs>
  • Occurs immediately before the document opens.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onBeforeOpen.register(function(args) {
      alert("A new document will be opened,\n payload type(binary or URL): " + args.type +",\n payload(bytes or string): " + args.payload);
    });
    viewer.open('Test.pdf');
    

    Returns EventFan<BeforeOpenEventArgs>

onError

  • get onError(): EventFan<ErrorEventArgs>
  • The event indicating error.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.addDefaultPanels();
    viewer.onError.register(handleError);
    viewer.open('Test.pdf');
    
    function handleError(eventArgs) {
        var message = eventArgs.message;
        if (message.indexOf("Invalid PDF structure") !== -1) {
            alert('Unable to load pdf document, pdf document is broken.');
        } else {
            alert('Unexpected error: ' + message);
        }
    }
    

    Returns EventFan<ErrorEventArgs>

options

  • The viewer options.

    example
    viewer.options.zoomByMouseWheel = { always: true };
    viewer.applyOptions();
    

    Returns Partial<ViewerOptions>

  • PDF viewer options.

    example
    viewer.options.zoomByMouseWheel = { always: true };
    viewer.applyOptions();
    

    Parameters

    Returns void

pageCount

  • get pageCount(): number
  • Gets pages count.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      alert("The document opened. Total number of pages: " + viewer.pageCount);
    });
    viewer.open('Test.pdf');
    

    Returns number

pageIndex

  • get pageIndex(): number
  • set pageIndex(val: number): void
  • Gets/sets the active page index.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      // Navigate page with index 9:
      viewer.pageIndex = 9;
    });
    viewer.open('Test.pdf');
    

    Returns number

  • Gets/sets the active page index.

    example
    var viewer = new GcPdfViewer('#root');
    viewer.onAfterOpen.register(function() {
      // Navigate page with index 9:
      viewer.pageIndex = 9;
    });
    viewer.open('Test.pdf');
    

    Parameters

    • val: number

    Returns void

rightSidebar

  • Gets right sidebar object. Use this object if you want to manipulate the right sidebar.

    example
    viewer.rightSidebar.show('expanded', 'reply-tool');
    viewer.rightSidebar.toggle();
    viewer.rightSidebar.hide();
    viewer.rightSidebar.expand();
    viewer.rightSidebar.collapse();
    

    Returns GcRightSidebar

rotation

  • get rotation(): number
  • set rotation(degrees: number): void
  • Gets/sets rotation in degrees.

    example
    var viewer = new GcPdfViewer('#root');
    // Register an onAfterOpen event handler:
    viewer.onAfterOpen.register(function() {
      // Apply 90 degree clockwise rotation:
      viewer.rotation = 90;
    });
    // Open document:
    viewer.open('Test.pdf');
    

    Returns number

  • Gets/sets rotation in degrees.

    example
    var viewer = new GcPdfViewer('#root');
    // Register an onAfterOpen event handler:
    viewer.onAfterOpen.register(function() {
      // Apply 90 degree clockwise rotation:
      viewer.rotation = 90;
    });
    // Open document:
    viewer.open('Test.pdf');
    

    Parameters

    • degrees: number

    Returns void

supportApi

  • get supportApi(): ISupportApi | null
  • Gets the SupportApi client.

    example
     var viewer = new GcPdfViewer('#root', { supportApi: 'api/pdf-viewer' } );
     // Contact server and get Support API version.
     viewer.serverVersion.then(function(ver) {
         alert("The SupportApi version is " + ver);
     });
    

    Returns ISupportApi | null

toolbarLayout

  • get toolbarLayout(): GcPdfViewerToolbarLayout
  • set toolbarLayout(toolbarLayout: GcPdfViewerToolbarLayout): void
  • Defines toolbar layout for different viewer modes: viewer, annotationEditor, formEditor.

    example
    viewer.toolbarLayout.viewer.default = ["open", "save"];
    viewer.toolbarLayout.annotationEditor.default = ["open", "save", "$split", "new-document", "edit-ink", "edit-text"];
    viewer.toolbarLayout.formEditor.default = ["open", "save", "$split", "edit-widget-tx-field", "edit-widget-tx-password"];
    viewer.applyToolbarLayout();
    

    Returns GcPdfViewerToolbarLayout

  • Defines toolbar layout for different viewer modes: viewer, annotationEditor, formEditor.

    example
    viewer.toolbarLayout.viewer.default = ["open", "save"];
    viewer.toolbarLayout.annotationEditor.default = ["open", "save", "$split", "new-document", "edit-ink", "edit-text"];
    viewer.toolbarLayout.formEditor.default = ["open", "save", "$split", "edit-widget-tx-field", "edit-widget-tx-password"];
    viewer.applyToolbarLayout();
    

    Parameters

    • toolbarLayout: GcPdfViewerToolbarLayout

    Returns void

undoCount

  • get undoCount(): number
  • Gets total undo levels count.

    example
    alert("Undo levels count is " + viewer.undoCount);
    

    Returns number

undoIndex

  • get undoIndex(): number
  • Gets current undo level index.

    example
    alert("The current Undo level index is " + viewer.undoIndex);
    

    Returns number

version

  • get version(): string
  • Returns the current version of the GcDocs PDF viewer.

    example
    alert("The GcPdfViewer version is " + viewer.version);
    

    Returns string

zoomMode

  • get zoomMode(): ZoomMode
  • set zoomMode(val: ZoomMode): void
  • Gets/sets the current zoom node. Accepted values are: 0 - Value, 1 - PageWidth, 2 - WholePage.

    // Set zoom mode to 'WholePage'
    viewer.zoomMode = 2;
    
    example
    // Set zoom mode to 'WholePage'
    viewer.zoomMode = 2;
    

    Returns ZoomMode

  • Gets/sets the current zoom node. Accepted values are: 0 - Value, 1 - PageWidth, 2 - WholePage.

    example
    // Set zoom mode to 'WholePage'
    viewer.zoomMode = 2;
    

    Parameters

    • val: ZoomMode

    Returns void

zoomValue

  • get zoomValue(): number
  • set zoomValue(val: number): void
  • Gets/sets the current zoom percentage level.

    example
    // Set zoom value to 150%
    viewer.zoomValue = 150;
    

    Returns number

  • Gets/sets the current zoom percentage level.

    example
    // Set zoom value to 150%
    viewer.zoomValue = 150;
    

    Parameters

    • val: number

    Returns void

Static i18n

  • get i18n(): i18n
  • Gets i18next instance which can be used to add viewer translations. See https://www.i18next.com for details about i18next framework.

    example
    function loadPdfViewer(selector) {
      // You can load translations from any source (see en-pdf-viewer.json for an example):
      var myTranslations = {
            "toolbar": {
                "open-document": "Open MY document",
                "pan": "My Pan tool",
            }
       };
       // Initialize translations:
       GcPdfViewer.i18n.init({
         resources: { myLang: { translation: myTranslations } }
       }).then(function(t) {
         // New translations initialized and ready to go!
         // Now create PDF viewer:
         var viewer = new GcPdfViewer(selector, { language: 'myLang' });
         viewer.addDefaultPanels();
         //viewer.open("sample.pdf");
       });
    }
    loadPdfViewer('#root');
    

    Returns i18n

Methods

addAnnotation

  • Add annotation to document.

    example
    // Below is the sample how to copy field with name "field1" and put it to the second page programmatically:
    // Find field widget with name field1:
    var resultData = await viewer.findAnnotation("field1", {findField: 'fieldName'});
    // Clone field:
    var clonedField = viewer.cloneAnnotation(resultData[0].annotation);
    // Change field name property:
    clonedField.fieldName = "field1Copy";
    // Add cloned field to the second page.
    viewer.addAnnotation(1, clonedField);
    

    Parameters

    Returns Promise<{ annotation: AnnotationBase; pageIndex: number }>

addAnnotationEditorPanel

  • addAnnotationEditorPanel(): void
  • Add annotation editor panel.

    example
    viewer.addAnnotationEditorPanel();
    

    Returns void

addArticlesPanel

  • addArticlesPanel(): void
  • Add articles panel.

    example
    viewer.addArticlesPanel();
    

    Returns void

addAttachmentsPanel

  • addAttachmentsPanel(): void
  • Add attachments panel.

    example
    viewer.addAttachmentsPanel();
    

    Returns void

addDefaultPanels

  • addDefaultPanels(): void
  • Add default set of sidebar panels with default order: 'Thumbnails', 'Search', 'Outline', 'Attachments', 'Articles'

    example
    viewer.addDefaultPanels();
    

    Returns void

addDocumentListPanel

  • addDocumentListPanel(): void
  • Adds document list panel to the Viewer with available document array specified in documentslist.json file (URL specified by documentListUrl option), located in the root directory of your application. You can specify service at the end point for documentListUrl option. The service should return JSON string with available documents array, e.g.: ["pdf1.pdf", "pdf2.pdf"]

    example

    Example content for the documentslist.json file:

    ["file1.pdf", "file2.pdf"].
    
    example
    var viewer = new GcPdfViewer("#root", { documentListUrl: "/documentslist.json" });
    viewer.addDocumentListPanel();
    

    Returns void

addFormEditorPanel

  • addFormEditorPanel(): void
  • Add form editor panel.

    example
     var viewer = new GcPdfViewer('#root', { supportApi: 'api/pdf-viewer' } );
     viewer.addDefaultPanels();
     viewer.addFormEditorPanel();
     

    Returns void

addOutlinePanel

  • addOutlinePanel(): void
  • Add outline panel.

    example
    viewer.addOutlinePanel();
    

    Returns void

addReplyTool

  • Enable the Text Annotation Reply Tool. Note, in order to enable ability to edit/remove or add existing replies you need to configure SupportApi, otherwise the Reply Tool will be in read-only mode.

    example
    viewer.addReplyTool('expanded');
    

    Parameters

    • Default value sidebarState: GcRightSidebarState = "collapsed"

      pass 'expanded' value if you wish the Reply tool to be expanded initially. Default value is collapsed.

    Returns void

addSearchPanel

  • addSearchPanel(): void
  • Add Search panel.

    example
    viewer.addSearchPanel();
    

    Returns void

addStickyNote

  • addStickyNote(position: GcSelectionPoint): void
  • Add sticky note to the document.

    example

    viewer.addStickyNote(viewer.toViewPortPoint({x: 50, y: 50, pageIndex: 0}));

    Parameters

    • position: GcSelectionPoint

      page relative point. Origin is top/left. Note, pageIndex must be specified.

    Returns void

addThumbnailsPanel

  • addThumbnailsPanel(): void
  • Add Thumbnails panel

    example
    viewer.addThumbnailsPanel();
    

    Returns void

applyOptions

  • applyOptions(): void
  • Call this method in order to apply changed options.

    example
    viewer.options.zoomByMouseWheel = { always: false, ctrlKey: true, metaKey: true };
    viewer.applyOptions();
    

    Returns void

applyToolbarLayout

  • applyToolbarLayout(): void
  • Call this method in order to apply changes in @see:toolbarLayout.

    example
    viewer.toolbarLayout.viewer.default = ["open", "save"];
    viewer.applyToolbarLayout();
    

    Returns void

beginUpdate

  • beginUpdate(): void
  • Suspends notifications until the next call to @see:endUpdate.

    example

    viewer.beginUpdate();

    deprecated

    Returns void

changeBoundsOrigin

  • changeBoundsOrigin(pageIndex: number, bounds: number[], srcOrigin: "TopLeft" | "BottomLeft", destOrigin: "TopLeft" | "BottomLeft"): number[]
  • This method changes coordinate system origin for rectangle given by parameter bounds and returns converted rectangle value;

    example
    var pageIndex = 0;
    var topLeftBounds = [0, 0, 200, 40];
    // Convert the topLeftBounds from TopLeft origin to BottomLeft origin
    // taking into account the viewport from the first page and store
    // the result in the bottomLeftBounds variable:
    var bottomLeftBounds = viewer.changeBoundsOrigin(pageIndex, topLeftBounds, 'TopLeft', 'BottomLeft');
    

    Parameters

    • pageIndex: number

      Page index (Zero based).

    • bounds: number[]

      bounds array: [x1, y1, x2, y2]

    • srcOrigin: "TopLeft" | "BottomLeft"

      Source coordinate system origin. Possible values are: 'TopLeft' or 'BottomLeft'.

    • destOrigin: "TopLeft" | "BottomLeft"

      Destination coordinate system origin. Possible values are: 'TopLeft' or 'BottomLeft'.

    Returns number[]

cloneAnnotation

  • Clone annotation or field given by parameter annotation.

    example
    // Below is the sample how to copy field with name "field1" and put it to the second page programmatically:
    // Find field widget with name field1:
    var resultData = await viewer.findAnnotation("field1", {findField: 'fieldName'});
    // Clone field:
    var clonedField = viewer.cloneAnnotation(resultData[0].annotation);
    // Change field name property:
    clonedField.fieldName = "field1Copy";
    // Add cloned field to the second page.
    viewer.addAnnotation(1, clonedField);
    

    Parameters

    Returns AnnotationBase

deletePage

  • deletePage(pageIndex?: undefined | number): void
  • Delete page.

    example
    // Delete page with index 3.
    viewer.deletePage(3);
    

    Parameters

    • Optional pageIndex: undefined | number

      page index to delete.

    Returns void

download

  • download(fileName?: undefined | string): void
  • Downloads the PDF document loaded in the Viewer to the local disk.

    example
    viewer.download();
    

    Parameters

    • Optional fileName: undefined | string

      the destination file name.

    Returns void

endUpdate

  • endUpdate(): void
  • Resumes notifications suspended by calls to @see:beginUpdate.

    example

    viewer.endUpdate();

    deprecated

    Returns void

execCopyAction

  • execCopyAction(buffer?: CopyBufferData): Promise<boolean>
  • Execute Copy action (Ctrl + C shortcut).

    example
    viewer.execCopyAction();
    

    Parameters

    • Optional buffer: CopyBufferData

      data to copy.

    Returns Promise<boolean>

execCutAction

  • execCutAction(buffer?: CopyBufferData): Promise<boolean>
  • Execute Cut action (Ctrl + X shortcut).

    example
    viewer.execCutAction();
    

    Parameters

    • Optional buffer: CopyBufferData

      data to cut.

    Returns Promise<boolean>

execDeleteAction

  • execDeleteAction(buffer?: CopyBufferData): Promise<boolean>
  • Execute Delete action (DEL shortcut).

    example
    viewer.execDeleteAction();
    

    Parameters

    • Optional buffer: CopyBufferData

      data to delete.

    Returns Promise<boolean>

execPasteAction

  • execPasteAction(point?: GcSelectionPoint): Promise<boolean>
  • Execute Paste action (Ctrl + V shortcut).

    example
    if(viewer.hasCopyData) {
      viewer.execPasteAction({x: 10, y: 10, pageIndex: 0});
    }
    

    Parameters

    • Optional point: GcSelectionPoint

      insert position.

    Returns Promise<boolean>

findAnnotation

  • findAnnotation(findString: string, findParams?: undefined | { findAll?: undefined | false | true; findField?: "id" | "title" | "contents" | "fieldName" | string; pageNumberConstraint?: undefined | number }): Promise<{ annotation: AnnotationBase; pageNumber: number }[]>
  • Find annotation(s) within opened document. Returns promise which will be resolved with search results.

    example
    // Find annotation with id '2R':
    viewer.findAnnotation("2R").then(function(dataArray) {
      if(dataArray[0])
        alert(`Annotation ${dataArray[0].annotation.id} found on page with index ${dataArray[0].pageNumber - 1}.`);
      else
        alert('Annotation not found.');
    });
    
    example
    // find all fields with name field1:
    viewer.findAnnotation("field1", {findField: 'fieldName', findAll: true}).then(function(dataArray) {
    
    });
    

    Parameters

    • findString: string

      Find query.

    • Optional findParams: undefined | { findAll?: undefined | false | true; findField?: "id" | "title" | "contents" | "fieldName" | string; pageNumberConstraint?: undefined | number }

      find parameters. By default annotation will be searched by id without page constraint.

    Returns Promise<{ annotation: AnnotationBase; pageNumber: number }[]>

getViewPort

  • getViewPort(pageIndex: number): { height: number; rotation: number; scale: number; viewBox: number[]; width: number }
  • Returns PDF page view port information.

    example
    // Get the viewport object for the first page:
    var viewPort = viewer.getViewPort(0);
    

    Parameters

    • pageIndex: number

      Page index (Zero based).

    Returns { height: number; rotation: number; scale: number; viewBox: number[]; width: number }

    Object containing following fields: { viewBox: // Original page bounds: [x1, y1, x2, y2]. // If you want to know original page's width/height, you can get it using viewBox values: // var pageWidth = viewBox[2] - viewBox[0]; // var pageHeight = viewBox[3] - viewBox[1]; width: // Current width of the page in user space (scale and rotation values are applied), height: // Current height of the page in user space (scale and rotation values are applied) scale: // Active scale value rotation: // Active rotation value }

    • height: number
    • rotation: number
    • scale: number
    • viewBox: number[]
    • width: number

goToFirstPage

  • goToFirstPage(): void
  • Go to the first page.

    example
    viewer.goToFirstPage();
    

    Returns void

goToLastPage

  • goToLastPage(): void
  • Go to the last page.

    example
    viewer.goToLastPage();
    

    Returns void

goToNextPage

  • goToNextPage(): void
  • Go to the next page.

    example
    viewer.goToNextPage();
    

    Returns void

goToPageNumber

  • goToPageNumber(pageNumber: number): void
  • Go to the page with the specific page number (numbering starts at 1).

    example
    // Go to the second page:
    viewer.goToPageNumber(2);
    

    Parameters

    • pageNumber: number

    Returns void

goToPrevPage

  • goToPrevPage(): void
  • Go to the previous page.

    example
    viewer.goToPrevPage();
    

    Returns void

loadAndScrollPageIntoView

  • loadAndScrollPageIntoView(pageIndex: number, destArray?: any[]): Promise<boolean>
  • The method loads the page at the index specified by the pageIndex parameter, and scrolls the page into the view.

    example
    // Load and display the first page:
    viewer.loadAndScrollPageIntoView(0);
    

    Parameters

    • pageIndex: number

      Destination page index.

    • Optional destArray: any[]

      The parameter is used for the @see:scrollPageIntoView method after the page is fully loaded.

    Returns Promise<boolean>

    Returns the boolean promise that resolves when the page is fully loaded (including text and annotation layers) and scrolled. A promise is resolved with false value when the page does not exist or an error occurs, otherwise the promise is resolved with true value.

loadDocumentList

  • loadDocumentList(): void
  • Load an updated document list into document list panel.

    example
    viewer.loadDocumentList();
    

    Returns void

newDocument

  • newDocument(params?: undefined | { confirm?: undefined | false | true; fileName?: undefined | string }): Promise<LoadResult | null>
  • Creates and opens a new blank document.

    example
    // Create a new blank document, name the file "test.pdf",
    // display a confirmation dialog if the active document has been modified.
    viewer.newDocument({ fileName: "test.pdf", confirm: true});
    

    Parameters

    • Optional params: undefined | { confirm?: undefined | false | true; fileName?: undefined | string }

      Parameters object: fileName - name of the file for a new document, confirm - show confirmation dialog if there are changes in the document.

    Returns Promise<LoadResult | null>

newPage

  • newPage(params?: undefined | { height?: undefined | number; pageIndex?: undefined | number; width?: undefined | number }): void
  • Adds a blank page to the document.

    example
    // Create a new blank page and insert it in the second position.
    viewer.newPage({pageIndex: 1});
    

    Parameters

    • Optional params: undefined | { height?: undefined | number; pageIndex?: undefined | number; width?: undefined | number }

      parameters object: width - page width in points, height - page height in points, pageIndex - page index.

    Returns void

open

  • open(file: any): Promise<LoadResult>
  • Open PDF document.

    example
    viewer.open("Documents/HelloWorld.pdf");
    

    Parameters

    • file: any

      URI to PDF document(string) or binary data(Uint8Array).

    Returns Promise<LoadResult>

openLocalFile

  • openLocalFile(): any
  • Show the file open dialog where the user can select the PDF file.

    example
    viewer.openLocalFile();
    

    Returns any

print

  • print(): void
  • Opens the browser's print document dialog box.

    example
    viewer.print();
    

    Returns void

redoChanges

  • redoChanges(): void
  • Redo document changes.

    example
    if(viewer.hasRedoChanges) {
      viewer.redoChanges();
    }
    

    Returns void

removeAnnotation

  • removeAnnotation(pageIndex: number, annotationId: string): Promise<boolean>
  • Remove annotation from document.

    example
    // Remove annotation with id '2R' located on the first page:
    viewer.removeAnnotation(0, '2R');
    

    Parameters

    • pageIndex: number
    • annotationId: string

    Returns Promise<boolean>

repaint

  • repaint(): void
  • Repaint visible pages.

    example
    viewer.repaint();
    

    Returns void

save

  • save(fileName?: undefined | string): Promise<boolean>
  • Downloads the modified PDF document to the local disk.

    example
    viewer.save('Test.pdf');
    

    Parameters

    • Optional fileName: undefined | string

      destination file name.

    Returns Promise<boolean>

saveChanges

  • saveChanges(): Promise<boolean>
  • Upload local changes to server.

    example
    viewer.saveChanges().then(function(result) {
      if(result) {
        alert("The document saved on the server.");
      } else {
        alert("Cannot save the document on the server.");
      }
    });
    

    Returns Promise<boolean>

scrollAnnotationIntoView

  • scrollAnnotationIntoView(pageIndex: number, annotation: AnnotationBase): any
  • Scroll annotation into view.

    example
    // Scroll the annotation located on the second page into view.
    viewer.scrollAnnotationIntoView(1, annotation);
    

    Parameters

    Returns any

scrollPageIntoView

  • scrollPageIntoView(params: { allowNegativeOffset?: undefined | false | true; destArray?: any[]; pageNumber: number }): void
  • Scroll page into view.

    example
    // Scroll to page 10.
    viewer.scrollPageIntoView( { pageNumber: 10 } )
    
    example
    // Scroll the annotation bounds rectangle into view:
    var rectangle = annotation.rect;
    var pagePosX = rectangle[0];
    var pagePosY = rectangle[1] + Math.abs(rectangle[3] - rectangle[1]);
    viewer.scrollPageIntoView({ pageNumber: pageIndex + 1, destArray: [null, { name: "XYZ" }, pagePosX, pagePosY, viewer.zoomValue / 100.0] });
    

    Parameters

    • params: { allowNegativeOffset?: undefined | false | true; destArray?: any[]; pageNumber: number }

      object. Scroll parameters: pageNumber - number. Page number. destArray - Array with destination information: destArray[0] // not used, can be null, pdf page reference (for internal use only). destArray[1] // contains destination view fit type name: { name: 'XYZ' } - Destination specified as top-left corner point and a zoom factor (the lower-left corner of the page is the origin of the coordinate system (0, 0)). { name: 'Fit' } - Fits the page into the window { name: 'FitH' } - Fits the widths of the page into the window { name: 'FitV' } - Fits the height of the page into a window. { name: 'FitR' } - Fits the rectangle specified by its top-left and bottom-right corner points into the window. { name: 'FitB' } - Fits the rectangle containing all visible elements on the page into the window. { name: 'FitBH' } - Fits the width of the bounding box into the window. { name: 'FitBV' } - Fits the height of the bounding box into the window. destArray[2] // x position offset destArray[3] // y position offset (note, the lower-left corner of the page is the origin of the coordinate system (0, 0)) destArray[4] // can be null, contains bounding box width when view name is FitR, contains scale when view name is XYZ, destArray[5] // can be null, contains bounding box height when view name is FitR

      • Optional allowNegativeOffset?: undefined | false | true
      • Optional destArray?: any[]
      • pageNumber: number

    Returns void

selectAnnotation

  • selectAnnotation(pageIndex: number | string, annotation?: AnnotationBase | string): Promise<boolean>
  • Select the annotation to edit.

    example
    // Select an annotation with id 2R:
    viewer.selectAnnotation("2R");
    
    example
    // Select an annotation with id 9R located on the last page:
    viewer.selectAnnotation(viewer.pageCount - 1, "9R");
    

    Parameters

    • pageIndex: number | string

      Page index (zero based) or annotation id.

    • Optional annotation: AnnotationBase | string

      Annotation id or annotation object itself.

    Returns Promise<boolean>

setTheme

  • setTheme(theme?: undefined | string): void
  • Set active viewer theme.

    example
    viewer.setTheme("themes/light-blue");
    

    Parameters

    • Optional theme: undefined | string

      theme name, specified in themes option.

    Returns void

submitForm

  • submitForm(submitUrl: string): void
  • Submit the form to the server.

    example
    viewer.submitUrl("/CustomFormHandler");
    

    Parameters

    • submitUrl: string

    Returns void

toViewPortPoint

  • toViewPortPoint(point: GcSelectionPoint): GcSelectionPoint
  • Converts point to page's viewport taking into account page scale.

    example

    viewer.addStickyNote(viewer.toViewPortPoint({x: 50, y: 50, pageIndex: 0}));

    Parameters

    • point: GcSelectionPoint

    Returns GcSelectionPoint

undoChanges

  • undoChanges(): void
  • Undo document changes.

    example
    if(viewer.hasUndoChanges) {
      viewer.undoChanges();
    }
    

    Returns void

unselectAnnotation

  • unselectAnnotation(): any
  • Reset annotation selection.

    example
    viewer.unselectAnnotation();
    

    Returns any

updateAnnotation

  • Update annotation.

    example
    // Update annotation on the first page (page index is 0):
    viewer.updateAnnotation(0, annotation1);
    

    Parameters

    Returns Promise<{ annotation: AnnotationBase; pageIndex: number }>

    Promise, resolved by updated annotation object.

updateAnnotations

  • Update multiple annotations at the same time.

    example
    // Update annotations on the second page (page index is 1):
    var annotationsToUpdate = [annotation1, annotation2];
    viewer.updateAnnotations(1, annotationsToUpdate);
    

    Parameters

    Returns Promise<{ annotations: AnnotationBase[]; pageIndex: number }>

    Promise, resolved by updated annotation objects.

updateRadioGroupValue

  • updateRadioGroupValue(fieldName: string, newValue: string, skipPageRefresh?: undefined | false | true): Promise<boolean>
  • Update radio buttons group given by parameter fieldName with new field value.

    example
    viewer.updateRadioGroupValue("radiogroup1", "3", true);
    

    Parameters

    • fieldName: string

      Grouped radio buttons field name

    • newValue: string

      New fieldValue

    • Optional skipPageRefresh: undefined | false | true

      boolean. Set to true if you don't need to update page display. Default is false.

    Returns Promise<boolean>

    Promise resolved by boolean value, true - radio buttons updated, false - an error occurred.