Skip to content

Commit

Permalink
Merge pull request #9 from yumauri/gotenberg_6.2.0
Browse files Browse the repository at this point in the history
Add new features from Gotenberg 6.2
  • Loading branch information
yumauri authored Feb 10, 2020
2 parents 15c837d + 04c3a92 commit 1457931
Show file tree
Hide file tree
Showing 10 changed files with 1,718 additions and 1,732 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ set(range('1-1'))
//...
```

or scale, using `set(scale)` (works with HTML, Markdown and URL conversions):

```typescript
//...
set(scale(0.75))
//...
```

## Markdown

```typescript
Expand Down
25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
{
"minNodeVersion": "10"
}
],
[
"pika-plugin-package.json",
{
"+author": "^",
"*files": [
"-bin/"
],
"-devDependencies": {}
}
]
]
},
Expand All @@ -42,23 +52,24 @@
},
"homepage": "https://github.com/yumauri/gotenberg-js-client#readme",
"dependencies": {
"@types/node": "^10.9.0",
"form-data": "^3.0.0"
},
"devDependencies": {
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.8.1",
"@pika/plugin-ts-standard-pkg": "^0.8.1",
"@types/jest": "^24.0.23",
"jest": "^24.9.0",
"@types/jest": "^25.1.2",
"@types/node": "^10.9.0",
"jest": "^25.1.0",
"pika-plugin-package.json": "^1.0.2",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"ts-node": "^8.5.4",
"tslint": "^5.20.1",
"ts-jest": "^25.2.0",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0",
"tslint-config-security": "^1.16.0",
"tslint-config-standard-plus": "^2.3.0",
"typescript": "^3.7.3",
"typescript": "^3.7.5",
"yaspeller": "^6.0.2"
},
"engines": {
Expand Down
6 changes: 6 additions & 0 deletions src/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export type HtmlRequestFields = {

// https://thecodingmachine.github.io/gotenberg/#html.page_ranges
pageRanges?: string

// https://thecodingmachine.github.io/gotenberg/#html.paper_size_margins_orientation_scaling
scale?: number
}

// markdown conversion form fields
Expand All @@ -75,6 +78,9 @@ export type OfficeRequestFields = {
// https://thecodingmachine.github.io/gotenberg/#url
export type UrlRequestFields = {
remoteURL?: string

// https://thecodingmachine.github.io/gotenberg/#html.paper_size_margins_orientation_scaling
scale?: number
}

// merge conversion doesn't have any form fields
Expand Down
7 changes: 7 additions & 0 deletions src/set-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
filename,
googleChromeRpccBufferSize,
range,
scale,
timeout,
webhook,
} from './set-helpers'
Expand Down Expand Up @@ -44,3 +45,9 @@ test('Test `range` function', () => {
range('1-1')(object)
expect(object).toEqual({ pageRanges: '1-1' })
})

test('Test `scale` function', () => {
const object = {}
scale(0.75)(object)
expect(object).toEqual({ scale: 0.75 })
})
9 changes: 9 additions & 0 deletions src/set-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ export const googleChromeRpccBufferSize = (
export const range = (range: string): FieldsModifier => (
fields: RequestFields
) => (fields.pageRanges = range)

/**
* Modifies `scale` form field
*
* https://thecodingmachine.github.io/gotenberg/#html.paper_size_margins_orientation_scaling
*/
export const scale = (scale: number): FieldsModifier => (
fields: RequestFields
) => (fields.scale = scale)
2 changes: 1 addition & 1 deletion src/to-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
LARGE_MARGINS,
LEGAL,
LETTER,
NO_MARGINS,
NORMAL_MARGINS,
NO_MARGINS,
TABLOID,
} from './page'

Expand Down
2 changes: 1 addition & 1 deletion src/to-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
LARGE_MARGINS,
LEGAL,
LETTER,
NO_MARGINS,
NORMAL_MARGINS,
NO_MARGINS,
TABLOID,
} from './page'

Expand Down
Binary file added test/scale.pdf
Binary file not shown.
31 changes: 31 additions & 0 deletions test/test_6.2_new_features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createWriteStream } from 'fs'
import {
a4,
convert,
gotenberg,
html,
pipe,
please,
scale,
set,
to,
} from '../src'

// need to run Gotenberg like this
// docker run --rm -p 3500:3000 thecodingmachine/gotenberg:6

pipe(
gotenberg('http://localhost:3500'),
convert,
html,
to(a4, {
top: 0,
right: 0.2, // ~5mm
bottom: 0,
left: 0.2, // ~5mm
}),
set(scale(0.5)),
please
)(`file://${__dirname}/statement.html`)
.then(pdf => pdf.pipe(createWriteStream(`${__dirname}/scale.pdf`)))
.catch(console.error)
Loading

0 comments on commit 1457931

Please sign in to comment.