1

I am working on a project for my school and I am trying to create a tool that can help teachers grade homework quicker with a homework grader. I was thinking of trying to find a way to differentiate normal texts vs texts/work created through Kami. Kami is a google extension that my school is using to allow students to submit work on already created PDFs. I am planning to locate each Kami texts and match it with the answer choices in order given by the teachers. However, I don't know if it is possible to scan a document and pick out only the Kami text. Thanks.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
meki
  • 11
  • 1
  • make sure to include the problem statement, current progress, current output and expected output to the question. – anees Sep 17 '20 at 23:50

2 Answers2

0
  1. To access the PDF directly you'll have to use the undocumented internal commands of the built-in PDF viewer (example for getSelectedText). You can try extracting the entire text by using the other commands from the source code of Chromium, inspect it yourself.

  2. An alternative method is to download the PDF from its URL (using the standard XMLHttpRequest or fetch, more info) and use some javascript library to parse the file.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
0

CEO of Kami here. This is a great question, and one that I'm happy to help you if you reach out to me (email is first name at kamiapp.com)

But to answer your question, Kami creates PDF-spec compliant text annotations when we embed our text boxes into the PDF. You can tell it's created with Kami because it's annotation object also includes a dictionary key "KAMI:comment_b64" or "KAMI:comment" in legacy cases. It's value includes a Base64 encoded string that you can decode to get a JSON object of the annotation.

Essentially you can decode it's data by doing this in Javascript:

var b64str = dict.get('KAMI:comment_b64');
var kamiComment = JSON.parse(decodeURIComponent(escape(atob(b64str))));

Or with this:

var kamiComment = JSON.parse(dict.get('KAMI:comment'));
Hengjie
  • 4,598
  • 2
  • 30
  • 35