Created
February 3, 2016 02:17
-
-
Save adamzuckerman/766523ec7d0bd7f533e3 to your computer and use it in GitHub Desktop.
JS to create JS to position PDF fields on a new document after copying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the number of widgets associated with a field | |
function getWidgetCount(fieldName) { | |
var field = getField(fieldName); | |
if (!field) { | |
return 0; | |
} | |
if (field.page.length > 0) { | |
return field.page.length; | |
} | |
return 1; | |
} | |
// Build a script that sets all of field's positions on the page | |
console.println("var f;"); | |
for (var pageNumber = 0; pageNumber < numPages; pageNumber++) | |
{ | |
for (var fieldNumber = 0; fieldNumber < numFields; fieldNumber ++) | |
{ | |
var fld = getField(getNthFieldName(fieldNumber)); | |
var widgetCount = getWidgetCount(fld.name); | |
for (var widgetNumber = 0; widgetNumber < widgetCount; widgetNumber++) | |
{ | |
var instField = getField(fld.name + "." + widgetNumber); | |
console.println("f = getField(\"" + instField.name + "\");"); | |
console.println("f.rect = [" + instField.rect + "];"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purpose
The purpose of this script is to create another script to assist with positioning entry fields copied from one PDF document to another.
Usage
Ctrl-J
to toggle the visibility of the window).Ctrl-M
).Background
A widget is an instance of a field on the document. For example, you have a PDF document that contains a field named
ContactFirstName
that is copied on multiple pages. Each instance/widget has a number associated with it on the Field list (e.g.,ContactFirstName#0
). It can be referenced in Javascript by usinggetField()
passing in the name of the field (ContactFirstName
) appended with a period (.
) and the instance number (e.g.,var field = getField("ContactFirstName.1");
would retrieve the 2nd instance of the field in the document).