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

              
                    <header>
      This pen uses the Annotations API component of the Adobe Embed API to simulate a real-time collaboration
      environment. Use the annotation tools in the top toolbar to add comments to one of the documents. You will see
      that comment appear on the other document in the same location and with the same properties. Comments created by
      the user on the left cannot be edited by the user on the right and vice versa effectively “locking” annotations
      and preventing the deletion of comments created by users other than the one creating them.
    </header>
    <div class="grid-container">
      <div id="leftPDF" class="grid-item passive"></div>
      <div id="rightPDF" class="grid-item passive"></div>
    </div>
    <script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
              
            
!

CSS

              
                body {
  width: 100%;
  height: calc(100vh - 150px);
  overflow-x: hidden;
  margin: 0;
  background-color: black;
}

header {
  width: 100%;
  max-width: 800px;
  height: 130px;
  padding: 10px;
  color: white;
  font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
    "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
  font-size: 1em;
  margin: 0 auto;
}

.grid-container {
  display: grid;
  grid-template-columns: auto auto;
  height: 100%;
  padding: 0px;
  column-gap: 10px;
}

.grid-item {
  padding: 10px;
}

.active {
  background-color: green;
}

.passive {
  background-color: red;
}

              
            
!

JS

              
                const urlToPDF =
  "https://documentcloud.adobe.com/view-sdk-demo/PDFs/Summary.pdf";
const fileID = "3A5E36C8AA950DCDEBFBFE46FFCDE0A6"; // The fileID binds the annotations to the document
const clientID = "e800d12fc12c4d60960778b2bc4370af";

var viewerOptions = {
  embedMode: "FULL_WINDOW",
  defaultViewMode: "FIT_PAGE",
  showDownloadPDF: false,
  showPrintPDF: false,
  showLeftHandPanel: true,
  showAnnotationTools: true,
  enableAnnotationAPIs: true
};

var annotationManagerConfig = {
  showToolbar: true,
  showCommentsPanel: true,
  downloadWithAnnotations: false,
  printWithAnnotations: true
};

var eventOptions = {
  listenOn: [
    "ANNOTATION_ADDED",
    "ANNOTATION_UPDATED",
    "ANNOTATION_DELETED",
    "ANNOTATION_SELECTED",
    "ANNOTATION_CLICKED"
  ]
};

var leftUserProfile = {
  userProfile: {
    name: "George Lang",
    firstName: "George",
    lastName: "Lang",
    email: ""
  }
};

var rightUserProfile = {
  userProfile: {
    name: "Conrad Simmms",
    firstName: "Conrad",
    lastName: "Simms",
    email: ""
  }
};

var leftAnnotationManager;
var rightAnnotationManager;
var activeViewer;

function setActive(div) {
  activeViewer = div.id;
  div.classList.add("active");
  div.classList.remove("passive");
}

function setPassive(div) {
  div.classList.add("passive");
  div.classList.remove("active");
}

function processEvent(event, side) {
  var eventAnnotationManager;
  var activeUser;
  if (side == "leftPDF") {
    eventAnnotationManager = leftAnnotationManager;
    targetAnnotationManager = rightAnnotationManager;
    activeUserName = leftUserProfile.userProfile.name;
  }
  if (side == "rightPDF") {
    eventAnnotationManager = rightAnnotationManager;
    targetAnnotationManager = leftAnnotationManager;
    activeUserName = rightUserProfile.userProfile.name;
  }
  if (event.data.creator.name != activeUserName) {
    eventAnnotationManager.unselectAnnotation();
  } else {
    if (activeViewer == side) {
      if (event.type == "ANNOTATION_ADDED") {
        targetAnnotationManager.addAnnotations([event.data]);
      } else if (event.type == "ANNOTATION_DELETED") {
        targetAnnotationManager.deleteAnnotations({
          annotationIds: [event.data.id]
        });
      } else if (event.type == "ANNOTATION_UPDATED") {
        targetAnnotationManager.deleteAnnotations({
          annotationIds: [event.data.id]
        });
        targetAnnotationManager.addAnnotations([event.data]);
      }
    }
  }
}

function previewPDF(view, pdfURL, fileID, side) {
  fetch(pdfURL)
    .then((res) => res.blob())
    .then((blob) => {
      view
        .previewFile(
          {
            // The file content
            content: { promise: Promise.resolve(blob.arrayBuffer()) },
            metaData: {
              fileName: pdfURL.split("/").slice(-1)[0],
              id: fileID
            }
          },
          viewerOptions
        )
        .then((view) => {
          view.getAnnotationManager().then((annotationManager) => {
            annotationManager.setConfig(annotationManagerConfig);
            addAnnotations(annotationManager);
            if (side == "leftPDF") {
              leftAnnotationManager = annotationManager;
              leftAnnotationManager.registerEventListener(function (event) {
                processEvent(event, "leftPDF");
              }, eventOptions);
            }
            if (side == "rightPDF") {
              rightAnnotationManager = annotationManager;
              rightAnnotationManager.registerEventListener(function (event) {
                processEvent(event, "rightPDF");
              }, eventOptions);
            }
          });
        });
    });
}

/*
    In practice you would replace this function with code that would retrieve the annotations for the document.
    */
function addAnnotations(annotationManager) {
  var annotationURLs = [
    "https://assets.codepen.io/4479906/AkiraTanaka.json"
  ];
  for (i = 0; i < annotationURLs.length; i++) {
    var annotURL = annotationURLs[i];
    fetch(annotURL)
      .then((response) => response.json())
      .then((json) => {
        annotationManager.addAnnotations([json]);
      });
  }
}

document.addEventListener("adobe_dc_view_sdk.ready", function () {
  // Set up mouse events to set each side to active or passive
  document.getElementById("leftPDF").addEventListener("mouseover", function () {
    setActive(this);
  });
  document.getElementById("leftPDF").addEventListener("mouseout", function () {
    setPassive(this);
  });
  document
    .getElementById("rightPDF")
    .addEventListener("mouseover", function () {
      setActive(this);
    });
  document.getElementById("rightPDF").addEventListener("mouseout", function () {
    setPassive(this);
  });
  // Create the views
  var leftAdobeDCView = new AdobeDC.View({
    clientId: clientID,
    divId: "leftPDF"
  });
  previewPDF(leftAdobeDCView, urlToPDF, fileID, "leftPDF");
  var rightAdobeDCView = new AdobeDC.View({
    clientId: clientID,
    divId: "rightPDF"
  });
  previewPDF(rightAdobeDCView, urlToPDF, fileID, "rightPDF");

  // Set up users
  leftAdobeDCView.registerCallback(
    AdobeDC.View.Enum.CallbackType.GET_USER_PROFILE_API,
    function () {
      return new Promise((resolve, reject) => {
        resolve({
          code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
          data: leftUserProfile
        });
      });
    }
  );
  rightAdobeDCView.registerCallback(
    AdobeDC.View.Enum.CallbackType.GET_USER_PROFILE_API,
    function () {
      return new Promise((resolve, reject) => {
        resolve({
          code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
          data: rightUserProfile
        });
      });
    }
  );
});

// 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);
    });
  }
})();

              
            
!
999px

Console