Skip to content

Commit

Permalink
Merge pull request #21 from mtlewis/2.1.0
Browse files Browse the repository at this point in the history
Prepare 2.1.0 release
  • Loading branch information
mtlewis authored Apr 5, 2019
2 parents a427873 + 47afc92 commit b9ed792
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.1.0

## New Features

- It's now possible to obtain the page, page count, and page size in the header and footer by passing a render function as the only child. See the readme for an example.

# 2.0.0

## Breaking changes
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,29 @@ const doc = (
);
```

### Dynamic Header and Footer

If you want to use the [dynamic header functionality](https://pdfmake.github.io/docs/document-definition-object/headers-footers/) in pdfmake, simply pass a render function as the only child of the header or footer:

```jsx
const doc = (
<document>
<header>
{(currentPage, pageCount) => (
<text>Page {currentPage} of {pageCount}.</text>
)}
</header>
<content>{/* ... */}</content>
</document>
);
```

The parameters are:

* `currentPage` - the 1-indexed page for which the content is being rendered
* `pageCount` - the total number of pages in the document
* `pageSize` - an object containing information about the dimensions of the page.

### Paragraphs

Paragraphs are defined using `text` tag.
Expand Down
2 changes: 1 addition & 1 deletion example/components/templates/mydocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export default (props, context) => (
pellentesque. Sed eget nisi eleifend, ullamcorper orci eget, eleifend
felis. Donec gravida enim dapibus nibh sollicitudin euismod.
</content>
<footer {...footerStyle}>© {context.config.copyrightYear}</footer>
<footer {...footerStyle}>{(page, count) => ${context.config.copyrightYear}. Page ${page} of ${count}.`}</footer>
</document>
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsx-pdf",
"version": "2.0.0",
"version": "2.1.0",
"main": "dst/index.js",
"description": "Generate modular PDFs using JSX.",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ describe('pdf', () => {
it('should contain the company name', () => {
expect(content).toContain('Example, Inc');
});

it('should contain page info in the footer', () => {
expect(content).toContain('Page 1 of 1.');
});
});
});

0 comments on commit b9ed792

Please sign in to comment.