Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- You can request a free trial license key, after you register, at Microblink Developer Hub -->
<blinkid-imagecapture-in-browser
    license-key="sRwAAAYHY2Rwbi5pb5ZgjD1QloirGkmBCZDF2DH6e8yVqo+rwfx7J3ZTi1MZfocQtbh4OdoJTgDJRNiK6ym8fSyNN0yVOVtL88LlRNCAdYGL6LD2e8EvO0n1i6ZQCHJkkwsy77SHEVFH7G2g/sUMEx5i3dHRj50n+CbmuPXgCIz6+jeCjo2zIcns6vrQ63h9GNF8qH9jPjDCq9hE5bFlEz3TRHEDbpxBoCsGCji1Ktt/7ns="
    recognizers="BlinkIdImageCaptureRecognizer"
    engine-location="https://unpkg.com/@microblink/blinkid-imagecapture-in-browser-sdk@5.18.0/resources/"
></blinkid-imagecapture-in-browser>
<div id="holder"></div>
              
            
!

CSS

              
                html,
body {
  margin: 0;
  padding: 0;

  width: 100%;
  height: 100%;
}

html {
  font-family: "Avenir Next", sans-serif;
}

body {
  background-color: #fff;
  box-sizing: border-box;

  display: flex;
  justify-content: center;
  align-items: center;

  padding: 20px;
}

blinkid-imagecapture-in-browser {
  /* Customization of UI - see variables in src/components/shared/styles/_globals.scss */
  /* --mb-component-background: red; */
}
              
            
!

JS

              
                import 'https://unpkg.com/@microblink/blinkid-imagecapture-in-browser-sdk@5.18.0/ui/dist/blinkid-imagecapture-in-browser/blinkid-imagecapture-in-browser.esm.js';

async function main() {
  // Important: if attributes or properties are changed, whole component is rerendered
  const el = document.querySelector( "blinkid-imagecapture-in-browser" );
  
  // Set absolute location of the worker file
  // IMPORTANT: function getWorkerLocation is a workaround for the CodePen since native Web Workers are not supported
  el.workerLocation = await getWorkerLocation('https://unpkg.com/@microblink/blinkid-in-browser-sdk@5.18.0/resources/BlinkIDWasmSDK.worker.min.js');

  // Create instance of client library - for more information see `client-library/README.md` file
  const client = new Client.Client(
    Client.ApiType.SelfHosted,
    {
      apiLocation: "https://demoapi.microblink.com"
    }
  );

  /**
   * UI component will extract a document image, which can be recognized on the backend.
   */
  el.addEventListener
  (
    "scanSuccess",
    ev =>
    {
      console.log( "scanSuccess: extracted image from WASM library", ev.detail );

      /**
       * [OPTIONAL] Filter document based on provided class info.
       *
       * Keep in mind that enums with codes for country, region and document types are
       * included in the WASM library.
       */
      /*if ( ev.detail.recognizer.classInfo.country === BlinkIDImageCaptureSDK.Country.CROATIA )
      {
        console.log( "What should I do with Croatian document?" );
      }*/

      // Show error or loading screen in UI component based on extracted image
      if ( !ev.detail.recognizer.frontSideCameraFrame )
      {
        el.setUiState( "ERROR" );
        return;
      }
      else
      {
        el.setUiState( "LOADING" );
      }

      // Send image to web API for processing
      const payload =
      {
        // Image from WASM library should be converted to Base64 from ImageData format.
        "imageSource": client.imageDataToBase64( ev.detail.recognizer.frontSideCameraFrame )
      };

      client.recognize( "/v1/recognizers/blinkid", payload )
        .then( ( results ) =>
        {
          const recognitionResults = results.response.data.result;
          console.log( "API recognition results", recognitionResults );

          if ( recognitionResults.recognitionStatus === "EMPTY" )
          {
            console.warn( "API processing returned empty results." );
            el.setUiState( "ERROR" );
            return;
          }

          // Do something with the results and notify the user
          el.setUiState( "SUCCESS" );
        } )
        .catch( ( error ) =>
        {
          console.error( "API recognition error", error );
          el.setUiState( "ERROR" );
        } );
    }
  );

  /**
   * Other events
   */
  el.addEventListener
  (
    "fatalError",
    ev => console.log( "fatalError", ev.detail )
  );

  el.addEventListener
  (
    "ready",
    ev => console.log( "ready", ev.detail )
  );

  el.addEventListener
  (
    "scanError",
    ev => console.log( "scanError", ev.detail )
  );

  el.addEventListener
  (
    "feedback",
    ev => console.log( "feedback", ev.detail )
  );
}

function getWorkerLocation(path) {  
  return new Promise((resolve) => {
    window.fetch(path)
      .then(response => response.text())
      .then(data => {
        const blob = new Blob( [ data ], { type: "application/javascript" } );
        const url = URL.createObjectURL( blob );
        resolve(url);
      });
  });
}

main();
              
            
!
999px

Console