function create_xfdf in FillPDF 5.0.x
Same name and namespace in other branches
- 8.4 xfdf.inc \create_xfdf()
- 6 xfdf.inc \create_xfdf()
- 7 xfdf.inc \create_xfdf()
Generates an XFDF file from values given in an associative array.
Parameters
string|null $file: The PDF file: URL or file path accepted. Use NULL to skip setting file-related properties.
array $info: Key/value pairs of the field data.
string $enc: The character encoding. Must match server output: default_charset in php.ini.
Return value
string The contents of the XFDF file.
1 call to create_xfdf()
- PdftkPdfBackend::mergeFile in src/
Plugin/ PdfBackend/ PdftkPdfBackend.php - Populate a PDF file with field data.
File
- ./
xfdf.inc, line 23 - Provides functions for creating XFDF files.
Code
function create_xfdf($file, array $info, $enc = 'UTF-8') {
$doc = new DOMDocument('1.0', $enc);
$xfdf_ele = $doc
->appendChild($doc
->createElement('xfdf'));
$xfdf_ele
->setAttribute('xmlns', 'http://ns.adobe.com/xfdf/');
$xfdf_ele
->setAttribute('xml:space', 'preserve');
$fields_ele = $xfdf_ele
->appendChild($doc
->createElement('fields'));
foreach ($info as $name => $value) {
$field_ele = $fields_ele
->appendChild($doc
->createElement('field'));
$field_ele
->setAttribute('name', $name);
$value_ele = $field_ele
->appendChild($doc
->createElement('value'));
$value_ele
->appendChild($doc
->createTextNode($value));
}
$ids_ele = $xfdf_ele
->appendChild($doc
->createElement('ids'));
if ($file) {
$ids_ele
->setAttribute('original', md5($file));
}
$ids_ele
->setAttribute('modified', \Drupal::time()
->getRequestTime());
if ($file) {
$f_ele = $xfdf_ele
->appendChild($doc
->createElement('f'));
$f_ele
->setAttribute('href', $file);
}
return $doc
->saveXML();
}