Add new feature, support scale

This commit is contained in:
yumauri
2020-02-10 20:20:11 +03:00
parent 15c837d3b3
commit 3dd8c5d47a
6 changed files with 61 additions and 0 deletions
+8
View File
@@ -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
+6
View File
@@ -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
@@ -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
+7
View File
@@ -3,6 +3,7 @@ import {
filename,
googleChromeRpccBufferSize,
range,
scale,
timeout,
webhook,
} from './set-helpers'
@@ -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
View File
@@ -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)
BIN
View File
Binary file not shown.
+31
View File
@@ -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)