Last active
April 9, 2018 13:22
-
-
Save Gergling/c5ab7976275e0240c2235a091ea05228 to your computer and use it in GitHub Desktop.
Takes a `pdftk` field dump and turns it into a PHP-copyable output.
This file contains hidden or 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
<?php | |
// Usage example: pdftk stuff.pdf dump_data_fields | php pdf-fields.php | |
$stdin = file('php://stdin'); | |
// print_r($stdin); | |
$data = []; | |
$i = 0; | |
foreach($stdin as $idx => $line) { | |
$chunks = explode(': ', $line); | |
$name = trim($chunks[0]); | |
if ($name === '---') { | |
$i += 1; | |
} | |
if (isset($chunks[1])) { | |
$value = trim($chunks[1]); | |
if ($name === 'FieldStateOption') { | |
$data[$i][$name][] = $value; | |
} else { | |
$data[$i][$name] = $value; | |
} | |
} | |
} | |
foreach($data as $i => $field) { | |
$fieldName = $field['FieldName']; | |
$options = ''; | |
if ($field['FieldType'] === 'Button') { | |
$options = ' // ' . implode(', ', $field['FieldStateOption']); | |
} | |
echo "'$fieldName' => '$i $fieldName',$options\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment