Add new feature, support page ranges
This commit is contained in:
@@ -181,6 +181,14 @@ set(filename('foo.pdf'), timeout(2.5))
|
||||
//...
|
||||
```
|
||||
|
||||
Also you can specify page ranges using `set(range)` (will not work with `merge`):
|
||||
|
||||
```typescript
|
||||
//...
|
||||
set(range('1-1'))
|
||||
//...
|
||||
```
|
||||
|
||||
## Markdown
|
||||
|
||||
```typescript
|
||||
@@ -268,7 +276,7 @@ const pdf = await toPDF(new URL('https://google.com'))
|
||||
|
||||
You can set remote url header (for example, for [authentication](https://github.com/thecodingmachine/gotenberg/issues/81) or [host specifying](https://github.com/thecodingmachine/gotenberg/issues/116)) with helper `add(header)` (or `add(headers)`, or both):
|
||||
|
||||
```javascript
|
||||
```typescript
|
||||
const toPDF = pipe(
|
||||
gotenberg('http://localhost:3000'),
|
||||
convert,
|
||||
|
||||
@@ -48,6 +48,9 @@ export type HtmlRequestFields = {
|
||||
marginLeft?: number
|
||||
marginRight?: number
|
||||
landscape?: boolean
|
||||
|
||||
// https://thecodingmachine.github.io/gotenberg/#html.page_ranges
|
||||
pageRanges?: string
|
||||
}
|
||||
|
||||
// markdown conversion form fields
|
||||
@@ -61,6 +64,9 @@ export type OfficeRequestFields = {
|
||||
// By default, it will be rendered with portrait orientation
|
||||
// https://thecodingmachine.github.io/gotenberg/#office.orientation
|
||||
landscape?: boolean
|
||||
|
||||
// https://thecodingmachine.github.io/gotenberg/#office.page_ranges
|
||||
pageRanges?: string
|
||||
}
|
||||
|
||||
// url conversion form fields
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
delay,
|
||||
filename,
|
||||
googleChromeRpccBufferSize,
|
||||
range,
|
||||
timeout,
|
||||
webhook,
|
||||
} from './set-helpers'
|
||||
@@ -37,3 +38,9 @@ test('Test `googleChromeRpccBufferSize` function', () => {
|
||||
googleChromeRpccBufferSize(9999)(object)
|
||||
expect(object).toEqual({ googleChromeRpccBufferSize: 9999 })
|
||||
})
|
||||
|
||||
test('Test `range` function', () => {
|
||||
const object = {}
|
||||
range('1-1')(object)
|
||||
expect(object).toEqual({ pageRanges: '1-1' })
|
||||
})
|
||||
|
||||
@@ -54,3 +54,13 @@ export const googleChromeRpccBufferSize = (
|
||||
googleChromeRpccBufferSize: number
|
||||
): FieldsModifier => (fields: RequestFields) =>
|
||||
(fields.googleChromeRpccBufferSize = googleChromeRpccBufferSize)
|
||||
|
||||
/**
|
||||
* Modifies `pageRanges` form field
|
||||
*
|
||||
* https://thecodingmachine.github.io/gotenberg/#html.page_ranges
|
||||
* https://thecodingmachine.github.io/gotenberg/#office.page_ranges
|
||||
*/
|
||||
export const range = (range: string): FieldsModifier => (
|
||||
fields: RequestFields
|
||||
) => (fields.pageRanges = range)
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,15 @@
|
||||
import { createWriteStream } from 'fs'
|
||||
import { add, convert, gotenberg, headers, pipe, please, url } from '../src'
|
||||
import {
|
||||
add,
|
||||
convert,
|
||||
gotenberg,
|
||||
headers,
|
||||
pipe,
|
||||
please,
|
||||
range,
|
||||
set,
|
||||
url,
|
||||
} from '../src'
|
||||
|
||||
// need to run Gotenberg like this
|
||||
// docker run --rm -p 3500:3000 thecodingmachine/gotenberg:6
|
||||
@@ -14,6 +24,7 @@ pipe(
|
||||
'Test-Header-2': 'Bar',
|
||||
})
|
||||
),
|
||||
set(range('1-1')),
|
||||
please
|
||||
)(`https://request.urih.com/`)
|
||||
.then(pdf => pdf.pipe(createWriteStream(`${__dirname}/headers.pdf`)))
|
||||
|
||||
Reference in New Issue
Block a user