Gnostice StarDocs API Demo Uses JavaScript SDK

Demo application to demonstrate the features of Gnostice StarDocs document processing and viewing API. This application uses the bundled JavaScript SDK to communicate with the server.

Get your free trial key here!

Code

// Setup connection
var stardocs = new Gnostice.StarDocs(
  new Gnostice.ConnectionInfo(
    'https://api.gnostice.com/stardocs/v1', 
    '', 
    ''), 
  new Gnostice.Preferences(new Gnostice.DocPasswordSettings(false));
);

// Authenticate
stardocs.auth.loginApp()
  .done(function(response) { /* Success */ })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });

Code

// Upload file
stardocs.storage.upload("upload-input") // Pass in the id of the input type="file" element
  .done(function(response) {
    documentUrl = response.documents[0].url;
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });

// Download file
stardocs.storage.download(documentUrl)
  .done(function() { // Browser download window gets launched })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });

// Delete file
stardocs.storage.delete(documentUrl)
  .done(function() { // File deleted })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 selected file

Code

// View file
stardocs.viewer.createView(documentUrl)
  .done(function(response) {
    var viewerUrl = response.url;
    // Load viewerUrl
    // Example: $("#view-frame").attr('src', viewerUrl);
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files

Code

// Merge files
stardocs.docOperations.merge(documentUrls)
  .done(function(response) {
    // response.documents[0] contains the merged file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 selected file at pages 1, 2, rest of the document

Code

// Split PDF file at given page ranges
stardocs.docOperations.splitRange(documentUrl, null, [{range: "1"}, {range: "2"}, {range: "3-"}])
  .done(function(response) {
    // response.documents array contains the generated file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 selected file at blank pages

Code

// Split file at every blank page
stardocs.docOperations.splitSeparatorPage(documentUrl)
  .done(function(response) {
    // response.documents array contains the generated file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to BMP format

Code

// Convert files to BMP image format
stardocs.docOperations.convertToBMP(documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to GIF format

Code

// Convert files to GIF image format
stardocs.docOperations.convertToGIF(documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to JPEG format

Code

// Convert files to JPEG image format
stardocs.docOperations.convertToJPEG(documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to PNG format

Code

// Convert files to PNG image format
stardocs.docOperations.convertToPNG(documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to TIFF format

Code

// Convert files to single-page TIFF image format
stardocs.docOperations.convertToTIFF(documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to multi-page TIFF format

Code

// Convert files to multi-page TIFF image format
stardocs.docOperations.convertToMTIFF("convertToSingleFile", documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 shortlisted files to PDF format

Code

// Convert files to PDF format
stardocs.docOperations.convertToPDF("convertToSingleFile", documentUrls)
  .done(function(response) {
	  // response.documents array contains the converted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 the selected file

Code

// Encrypt (password protect) PDF file
stardocs.docOperations.encrypt(documentUrl, "existingPassword", "AES_128bit", "newOpenPassword", "newPermissionsPassword")
  .done(function(response) {
	  // response.documents[0] contains the encrypted file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });
 text from the selected file

Code

// Redact text from PDF file
stardocs.docOperations.redactText(documentUrl, null, null, "literal", [{ text: "sensitive", caseSensitive: false, wholeWord: true }])
  .done(function(response) {
	  // response.documents[0] contains the modified file details (url, fileName, ...)
  })
  .fail(function(httpStatusCode, httpErrorMessage, response) { /* Handle error */ });