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

              
                <div class="container">
    <div id="search-bar">
      <div class="input-group">
        <div class="input-group-prepend">
          <span class="input-group-text">Search Term</span>
        </div>
        <input type="text" class="form-control" id="search-term" placeholder="financial" value="financial">
      </div>

      <div>
        <button type="button" class="btn btn-primary" onclick="executeSearch()">Search</button>
        <button type="button" class="btn btn-secondary" onclick="searchPrevious()">&lt;&lt;</button>
        <div class="search-location"><span id="search-index"></span> of <span id="search-total"></span></div>

        <button type="button" class="btn btn-secondary" onclick="searchNext()">&gt;&gt;</button>
        <button type="button" class="btn btn-primary" onclick="searchClear()">Clear</button>
      </div>
    </div>
    <div id="embeddedView"></div>
  </div>
  <script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
              
            
!

CSS

              
                body {
    width: 100%;
    height: 100vh;
    overflow-x: hidden;
    margin: 0;
    background-color: black;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.container {
    width: 100%;
    max-width: unset;
    height: 100%;
    display: flex;
    align-content: center;
    justify-content: center;
    flex-direction: column;
    padding: 0;
}

#search-bar {
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    padding: 20px;
    background-color: lightgray;
    gap: 15px;
    border-bottom: 1px solid darkgrey;
}

#embeddedView {
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-content: center;
    flex-direction: column;
    flex-grow: 1;
}

.input-group {
    width: unset;
    flex-grow: 1;
}

.input-group-prepend {
    display: unset;
}

.search-location {
    display: none;
}
              
            
!

JS

              
                const ppdfEmbedAPILoader = {
  displayPDF: function (urlToPDF) {
    fetch(urlToPDF)
      .then(ppdfEmbedAPILoader.errorHandler)
      .then(response => {
        if (response.ok) {
          const contentType = response.headers.get("content-type");
          if (contentType) {
            if (contentType == "application/pdf") { // Check that the response is actually a PDF file
              return response.blob().then(blob => {
                ppdfEmbedAPILoader.embedView(blob.arrayBuffer(), ppdfEmbedAPILoader.fileNameFromURL(urlToPDF)); // If it is, show it.
              })
            }
            if (contentType.includes("text") == true) { // The result might be a Base64 encoded PDF
              return response.text().then(text => {
                if (text.startsWith("JVBERi0") == true) { // Test the string for the "application/pdf" mime type signature  
                  ppdfEmbedAPILoader.embedView(Promise.resolve(ppdfEmbedAPILoader.base64ToArrayBuffer(text)), ppdfEmbedAPILoader.defaultFileName); // If it is, show it.
                }
                else {
                  if (typeof ppdfNotaPDF === "function") {
                    ppdfNotaPDF(response); // modify the DOM with your own function here
                  }
                  throw Error("The MIME type of the requested content is " + response.headers.get("Content-Type") + ". The content must be MIME type application/pdf.");
                }
              })
            }
          }
        }
      })
      .catch((error) => {
        console.log(error);
      });
  },
  embedView: function (contentPromise, pdfFileName) {
    if (window.adobeDCView) {
      window.adobeDCView = null;
    }
    window.adobeDCView = new AdobeDC.View({
      clientId: ppdfEmbedAPILoader.clientId,
      divId: ppdfEmbedAPILoader.divId
    });
    window.adobeFilePreview = adobeDCView.previewFile(
      {
        content: { promise: contentPromise },
        metaData: { fileName: pdfFileName }
      },
      ppdfEmbedAPILoader.viewerOptions
    )
  },
  base64ToArrayBuffer: function (base64) {
    var bin = window.atob(base64);
    var len = bin.length;
    var uInt8Array = new Uint8Array(len);
    for (var i = 0; i < len; i++) {
      uInt8Array[i] = bin.charCodeAt(i);
    }
    return uInt8Array.buffer;
  },
  fileNameFromURL: function (urlToPDF) {
    var fileName = urlToPDF.split("/").slice(-1)[0];
    if (fileName.toLowerCase().endsWith(".pdf") == false) {
      fileName = ppdfEmbedAPILoader.defaultFileName
    }
    return fileName;
  },

  errorHandler: function (response) {
    if (!response.ok) {
      if (typeof ppdfBadResponse === "function") {
        ppdfBadResponse(response); // modify the DOM with your own function here
      }
      throw Error("Fetch Response Status: " + response.status + " - " + response.statusText);
    }
    return response;
  },

}

ppdfEmbedAPILoader.clientId = "e800d12fc12c4d60960778b2bc4370af";
ppdfEmbedAPILoader.viewerOptions = {
  embedMode: "FULL_WINDOW",
  defaultViewMode: "FIT_PAGE",
  showDownloadPDF: false,
  showPrintPDF: false,
  showLeftHandPanel: true,
  showAnnotationTools: false,
  enableSearchAPIs: true
};
ppdfEmbedAPILoader.divId = "embeddedView"; // required
ppdfEmbedAPILoader.defaultFileName = "Untitled.pdf"; // required


document.addEventListener("adobe_dc_view_sdk.ready", (event) => {
  ppdfEmbedAPILoader.displayPDF("https://documentcloud.adobe.com/view-sdk-demo/PDFs/Bodea Brochure.pdf");
});

function executeSearch() {
  var previewFilePromise = window.adobeFilePreview;
  previewFilePromise.then(adobeViewer => {
    adobeViewer.getAPIs().then(apis => {
      if ($("#search-term").val().length == 0) {
        $("#search-term").val($("#search-term").attr("placeholder"));
      }
      apis.search($("#search-term").val()).then(searchObject => {
        window.searchObject = searchObject;
        searchObject.onResultsUpdate(onResultsUpdate)
          .catch(error => onFail(error));
      })
        .catch(error => onFail(error));
    });
  });
}

function onResultsUpdate(result) {
  console.log(JSON.stringify(result));
  updateSearchLocation(result)
}

function searchNext() {
  window.searchObject.next();
}

function searchPrevious() {
  window.searchObject.previous();
}

function searchClear() {
  window.searchObject.clear();
  $(".search-location").css("display", "none");
  $("#search-term").val("");
}

function onFail(error) {
  console.log(JSON.stringify(error));
}

function updateSearchLocation(result) {
  $(".search-location").css("display", "inline");
  $("#search-index").text(result.currentResult.index);
  $("#search-total").text(result.totalResults);
}

function ppdfBadResponse(response) {
  var messageElement = document.createElement("div");
  messageElement.classList.add("error-message");
  messageElement.appendChild(document.createTextNode("Fetch Response Status: " + response.status + " - " + response.statusText));
  document.getElementById("embeddedView").clearChildren();
  document.getElementById("embeddedView").appendChild(messageElement);
}

function ppdfNotaPDF(response) {
  var messageElement = document.createElement("div");
  messageElement.classList.add("error-message");
  messageElement.appendChild(document.createTextNode("The MIME type of the requested content is " + response.headers.get("Content-Type") + ". The content must be MIME type application/pdf."));
  document.getElementById("embeddedView").clearChildren();
  document.getElementById("embeddedView").appendChild(messageElement);
}

// Helper functions
// Add arrayBuffer if necessary i.e. Safari
(function () {
  if (Blob.arrayBuffer != "function") {
    Blob.prototype.arrayBuffer = myArrayBuffer;
  }

  function myArrayBuffer() {
    return new Promise((resolve) => {
      let fileReader = new FileReader();
      fileReader.onload = () => {
        resolve(fileReader.result);
      };
      fileReader.readAsArrayBuffer(this);
    });
  }
})();

if (typeof Element.prototype.clearChildren === 'undefined') {
  Object.defineProperty(Element.prototype, 'clearChildren', {
    configurable: true,
    enumerable: false,
    value: function () {
      while (this.firstChild) this.removeChild(this.lastChild);
    }
  });
}

              
            
!
999px

Console