<commit_before># XFDF
A Node.js module for creating Adobe XFDF files.

[![Build Status](https://travis-ci.org/ScottONeal/xfdf.svg?branch=master)](https://travis-ci.org/ScottONeal/xfdf)

```
var xfdf = require('xfdf')

var builder = new xfdf({ pdf: 'Document.pdf' });

builder.addField({ name: 'firstname', value: 'John'});

console.log(builder.generate());
```

calling generate() will create:

```
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <f href="Document.pdf"/>
  <fields>
    <field name="firstname">
      <value>John</value>
    </field>
  </fields>
</xfdf>
```

## Options

When constructing an xfdf builder there are several options that can be passed.
```
  new xfdf({
    pdf: 'path/to/document.pdf',
    translateBools: true,
    format: {
      pretty: false,
      indent: '  ',
      newline: '\r\n'
    }
  });
```

#### pdf
This is the location of the template pdf to be refrenced in the xfdf document.

#### translateBools
This will translate booleans in a javascript literal to 'Yes' or 'Off', which are used to flag checkboxes or radios in Adobe forms

*default:* true

#### format
This module uses [xmlbuilder](https://github.com/oozcitak/xmlbuilder-js) to construct the xfdf xml document. xmlbuilder has several formating options which can be specified when creating the xml document. You can see those options [here](https://github.com/oozcitak/xmlbuilder-js/wiki#converting-to-string)

*default:* 
```
  pretty: true
  indent: '  '
  newline: '\n'
```

## Methods

#### addField({data})

Will add a field to xfdf document.
Argument should be a hash with two keys: name, value;
```
  builder.addField({ name: 'FieldName', value: 'FieldValue'});
```

#### addFields([data])

This will accept an array of field objects to be added to the document.
```
  builder.addFields([
    { name: 'first_name', value: 'John'},
    { name: 'last_name' , value: 'Doe' },
  ]);
```

#### fromJSON({data})

You can use this method to pass an entire javascript literal to be consumed by the XFDF builder.
Format of object should be:
```
  {
    fields: [
      {name: 'FieldName', value: 'FieldValue'}
    ]
  }
```

#### fromJSONFile('path', callback)

Used to slurp a correctly formatted json file.
*Usage:*
```
  builder.fromJSONFile('/path/to/data.json', function(err) {
    if ( !err ) 
      builder.generate(); 
  });
```
<commit_msg>Added install instructions to README.<commit_after># XFDF
A Node.js module for creating Adobe XFDF files.

[![Build Status](https://travis-ci.org/ScottONeal/xfdf.svg?branch=master)](https://travis-ci.org/ScottONeal/xfdf)

## Installation
```
npm install xfdf
```
Always good to run tests
```
npm test
```

```
var xfdf = require('xfdf')

var builder = new xfdf({ pdf: 'Document.pdf' });

builder.addField({ name: 'firstname', value: 'John'});

console.log(builder.generate());
```

calling generate() will create:

```
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <f href="Document.pdf"/>
  <fields>
    <field name="firstname">
      <value>John</value>
    </field>
  </fields>
</xfdf>
```

## Options

When constructing an xfdf builder there are several options that can be passed.
```
  new xfdf({
    pdf: 'path/to/document.pdf',
    translateBools: true,
    format: {
      pretty: false,
      indent: '  ',
      newline: '\r\n'
    }
  });
```

#### pdf
This is the location of the template pdf to be refrenced in the xfdf document.

#### translateBools
This will translate booleans in a javascript literal to 'Yes' or 'Off', which are used to flag checkboxes or radios in Adobe forms

*default:* true

#### format
This module uses [xmlbuilder](https://github.com/oozcitak/xmlbuilder-js) to construct the xfdf xml document. xmlbuilder has several formating options which can be specified when creating the xml document. You can see those options [here](https://github.com/oozcitak/xmlbuilder-js/wiki#converting-to-string)

*default:* 
```
  pretty: true
  indent: '  '
  newline: '\n'
```

## Methods

#### addField({data})

Will add a field to xfdf document.
Argument should be a hash with two keys: name, value;
```
  builder.addField({ name: 'FieldName', value: 'FieldValue'});
```

#### addFields([data])

This will accept an array of field objects to be added to the document.
```
  builder.addFields([
    { name: 'first_name', value: 'John'},
    { name: 'last_name' , value: 'Doe' },
  ]);
```

#### fromJSON({data})

You can use this method to pass an entire javascript literal to be consumed by the XFDF builder.
Format of object should be:
```
  {
    fields: [
      {name: 'FieldName', value: 'FieldValue'}
    ]
  }
```

#### fromJSONFile('path', callback)

Used to slurp a correctly formatted json file.
*Usage:*
```
  builder.fromJSONFile('/path/to/data.json', function(err) {
    if ( !err ) 
      builder.generate(); 
  });
```

{'fraction_non_alphanumeric': 0.15989435188947582, 'fraction_numerical': 0.001219016659894352, 'mean_word_length': 3.812316715542522, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 2, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '846502', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1607, 'n_words': 503}