Wednesday, April 4, 2018

Form-fillable PDF character sheets--a suggestion

SYSTEM: Any

So my daughter has conned—er, convinced—another friend to join this occasional D&D thing at our house. (My wife has graciously given up every other one of our Sunday Afternoon Games sessions to this. And my daughter created a character for her friend, and sent me a PDF of the form-filled character sheet.

And to do anything with it, I have to retype the darned thing. Re-enter it, re-write it, re-do it. Yuck.

So, here's my request to the universe at large. All form-fillable character sheets need to have a button that reads the contents of all the fields and assembles them into one field that can be copied and put in another place.

It's not impossible: I just did it for ICONS (though I won't be sharing that version, because it also contains a character generator which I don't want to release, because it'll cut into other people's revenue).

So, folks, if you're creating a form-fillable character sheet, put a non-printing button on it and a field that holds the output string.

Here's one way to do it, which isn't even the best way. It's not at ECMAscript 6 levels because Acrobat or Acrobat Reader is down at ECMAscript 3 (I think). And also it's not great because I picked up my JavaScript on street corners, along with other misinformation about sex, drugs, and lock-picking.

var summaryShow = false;

function hideSummary() {
  var sumField = this.getField("Summary");
  sumField.display = display.hidden;
  sumField.readonly = true;
  sumField.value = "";
  summaryShow = false;
}
function showSummary() {
  var fieldList = ["Name", "of", "every", "field", "in", "the", "order", "you", "want", "them"];

  var outputStr = "";

  for (var i=0; i < fieldList.length; i++) {
    outputStr += this.getField(fieldList[i]).value + " ";
    if (i%5 === 0) {outputStr += "\r";}
  }

  var sumField = this.getField("Summary");
  sumField.display = display.visible;
  sumField.readonly = false;
  sumField.value = outputStr;
  summaryShow = true;
}

You add the Summary field as a multi line text field, and then make it display.hidden and readonly.

Then you put in the button so it's visible but doesn't print, and when pressed (on a mouse up event), the button checks summaryShow. If true, it runs hideSummary() and if false it runs showSummary(). (There's lots of things you can do to make it better: format the output with until.printf(), for instance, or extract values from listboxes and buttons, but this is a decent start. Not to mention structural things you could do...I'm sure with twenty minutes thought I could come up with something better than this.)

No comments:

Post a Comment