Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ const anvilClient = new Anvil({ apiKey })

Fills a PDF with your JSON data.

First, you will need to have uploaded a PDF to Anvil. On the `API Info` tab of your PDF template's page, you you find the PDF template's eid:
First, you will need to have uploaded a PDF to Anvil. You can find the PDF template's eid on the `API Info` tab of your PDF template's page:

<img width="725" alt="pdf-template-id" src="https://user-images.githubusercontent.com/69169/73583957-d8dec180-4449-11ea-9ea3-d426677cb881.png">

An example
An example:

```js
const eid = 'kA6Da9CuGqUtc6QiBDRR'
// Your API key from your Anvil organization settings
const apiKey = '7j2JuUWmN4fGjBxsCltWaybHOEy3UEtt'

// JSON data to fill the PDF
const exampleData = {
const payload = {
"title": "My PDF Title",
"fontSize": 10,
"textColor": "#CC0000",
Expand All @@ -80,7 +80,7 @@ const exampleData = {
}
}
const anvilClient = new Anvil({ apiKey })
const { statusCode, data } = await anvilClient.fillPDF(eid, exampleData)
const { statusCode, data } = await anvilClient.fillPDF(eid, payload)
```

* `pdfTemplateEID` (String) - The eid of your PDF template from the Anvil UI
Expand Down
10 changes: 4 additions & 6 deletions example/script/fill-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { run } from './env'
import Anvil from '../../src/index'

const argv = require('yargs')
.usage('Usage: $0 [-e local|staging|production] castEid token jsonPath.json')
.usage('Usage: $0 [-e local|production] castEid token jsonPath.json')
.alias('e', 'endpoint')
.demandCommand(3).argv

Expand All @@ -42,16 +42,14 @@ const baseURL = endpoints[endpointKey || 'production']
const exampleData = JSON.parse(fs.readFileSync(jsonPath, { encoding: 'utf8' }))

async function main () {
const client = new Anvil({
baseURL,
apiKey,
})
const client = new Anvil({ baseURL, apiKey })

const { statusCode, data } = await client.fillPDF(eid, exampleData)

if (statusCode === 200) {
const testDir = __dirname
fs.writeFileSync(path.join(testDir, 'fill.output.pdf'), data, { encoding: null })
const outputFilePath = path.join(testDir, 'fill.output.pdf')
fs.writeFileSync(outputFilePath, data, { encoding: null })
} else {
console.log(statusCode, JSON.stringify(data, null, 2))
}
Expand Down