0

Could a Chrome Extension add a script to an existing annotation created by PSPDFKit in order to add a string to an existing annotation instance/bubble?

PSPDFKit APIs are here: https://pspdfkit.com/guides/web/samples/javascript-pdf-annotations/

Example annotation / uploaded doc is here: https://pspdfkit.com/demo/hello

Here's a visual on where the Chrome Extension would ideally place text: enter image description here

TinyMCE and other advanced editors can be reached (see example below) but this one is more obscure. Any ideas or direction from the Extension gurus?

Example TinyMCE:

var script = document.createElement('script');
script.textContent = "console.log('AP talks to tinyMCE1...'); tinymce.activeEditor.execCommand('mceInsertContent', false, " + JSON.stringify(request.sValue) + ");tinymce.activeEditor.execCommand('mceInsertContent', false, ' - just more.')";
(document.head||document.documentElement).appendChild(script);
script.remove();
11teenth
  • 1,853
  • 1
  • 15
  • 28
  • Thank so much for taking a look! To be more specific, I've added an image from the public test content. My goal is simply to insert text, programmatically, into the annotation - the yellow post-it note. With other editors, like TinyMCE, a script can access the solution's APIs to add text or HTML. I'm not trying to edit the underlying doc/image. – 11teenth Aug 28 '23 at 21:08
  • If you're allowed to call out to a command line tool, the latest version of cpdf can round-trip annotations via JSON. You would run `cpdf -list-annotations-json in.pdf > out.json` then modify the JSON file as appropriate, then run `cpdf -remove-annotations in.pdf AND -set-annotations-json out.json -o out.pdf`. But perhaps you cannot get access to cpdf from within a browser extension. – johnwhitington Aug 29 '23 at 11:28
  • Really appreciate you all taking a look. Assume a human has clicked to create the annotation and the cursor is blinking in the yellow DIV. Can a script (as @johnwhitington begins to suggest), talk to PSPDF APIs and add text (saving the user from typing text). The use case here is a template manager - wanting to insert canned text into the annotation by clicking a button in a Chrome Extension, to avoid typing the same things over and over. – 11teenth Aug 29 '23 at 12:43
  • 1
    No I don't think so. It would be a case of saving the file, processing it through cpdf then reloading it. Not really suitable for this interactive use case you describe. Why not go old fashioned and just simulate typing on the keyboard? – johnwhitington Aug 29 '23 at 18:33
  • Thank you! My Extension does insert text in a variety of ways. The editor in PSDPFPDPFDSDFP has a 'state' and doesn't recognize text injected into it through a variety of methods I've used with other editors... – 11teenth Aug 30 '23 at 11:33

0 Answers0