Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Code_Examples

bmatzelle edited this page · 9 revisions

Below are a few simple examples using VuzitJava.

Upload Example

Below is an example that shows how include Vuzit and upload a simple file:


com.vuzit.Service.setPublicKey("YOUR_PUBLIC_API_KEY");
com.vuzit.Service.setPrivateKey("YOUR_PRIVATE_API_KEY");

com.vuzit.Document doc = com.vuzit.Document.upload("c:/path/to/document.pdf");  

System.out.println("Document id: " + doc.getId());

Load Document Example

Below shows how to load a document.


com.vuzit.Service.setPublicKey("YOUR_PUBLIC_API_KEY");
com.vuzit.Service.setPrivateKey("YOUR_PRIVATE_API_KEY");

com.vuzit.Document doc = com.vuzit.Document.find("DOCUMENT_ID");

System.out.println("Document id: " + doc.getId());
System.out.println("Document title: " + doc.getTitle());

Search Documents Example


com.vuzit.Document[] docs = com.vuzit.Document.findAll(new com.vuzit.OptionList().add("query", "john smith"));

for(int i = 0; i < docs.length; i++)
{
  com.vuzit.Document doc = docs[i];
  System.out.println("Document id: " + doc.Id);
  System.out.println("Document title: " + doc.Title);
}

Delete (destroy) Document

Example for deleting a document.


com.vuzit.Service.setPublicKey("YOUR_PUBLIC_API_KEY");
com.vuzit.Service.setPrivateKey("YOUR_PRIVATE_API_KEY");

com.vuzit.Document.destroy("DOCUMENT_ID");

Upload and View with HTML

Complete end-to-end example for uploading a document and viewing it with the JavaScript API using JSP:


  // Set the public and private keys
  com.vuzit.Service.setPublicKey("YOUR_PUBLIC_API_KEY");  
  com.vuzit.Service.setPrivateKey("YOUR_PRIVATE_API_KEY");  

  // Substitute the code below with the Vuzit document ID.  
  String documentId = "XXXXXXX";
  java.util.Date date = new java.util.Date();

  // Show document "timestamp" parameter
  long timestamp = com.vuzit.Service.epochTime(date);

  // Show document "signature" parameter
  String signature = com.vuzit.Service.signature("show", documentId, date);

  // Creates a URL-encoded signature
  String encodedSig = java.net.URLEncoder.encode(signature, "UTF-8");
  %>
  <html>
    <head>
      <link href="http://vuzit.com/stylesheets/Vuzit-2.10.css" rel="Stylesheet" type="text/css" />
      <script src="http://vuzit.com/javascripts/Vuzit-2.10.js" type="text/javascript"></script>
      <script type="text/javascript">
        // Called when the page is loaded.  
        function initialize()  {
          vuzit.Base.apiKeySet("<%= com.vuzit.Service.getPublicKey() %>"); 
          var options = {signature: '<%= encodedSig %>', 
                         timestamp: '<%= timestamp %>', ssl: true}
          var viewer = vuzit.Viewer.fromId("<%= documentId %>", options);

          viewer.display(document.getElementById("vuzit_viewer"), { zoom: 1 });
        }
      </script>
    </head>
    <body onload="initialize()">
      <div id="vuzit_viewer" style="width: 650px; height: 500px;"></div>
    </body>
  </html>

Something went wrong with that request. Please try again.