Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PDF component with preview and more examples #79

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 9 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ $ npm install react-to-pdf
## Examples

- [Code Sandbox demo](https://codesandbox.io/s/ancient-violet-sznj9q?file=/src/App.tsx)
- [Using `usePDF` hook](blob/main/examples/ExampleUsePDF.tsx)
- [Using default function](blob/main/examples/ExampleFunction.tsx)
- [Multipage support](blob/main/examples/ExampleMultipage.tsx)
- [Advanced options](blob/main/examples/ExampleAdvanced.tsx)
- [Using `usePDF` hook](https://github.com/ivmarcos/react-to-pdf/blob/main/examples/ExampleUsePDF.tsx)
- [Using default function](https://github.com/ivmarcos/react-to-pdf/blob/main/examples/ExampleFunction.tsx)
- [Multipage support](https://github.com/ivmarcos/react-to-pdf/blob/main/examples/ExampleMultipage.tsx)
- [Advanced options](https://github.com/ivmarcos/react-to-pdf/blob/main/examples/ExampleAdvanced.tsx)

## Usage

Expand All @@ -47,6 +47,7 @@ const Component = () => {
)
}
```
[Code Sandbox demo](https://codesandbox.io/s/ancient-violet-sznj9q?file=/src/App.tsx)

**Using default function**

Expand All @@ -66,6 +67,7 @@ const Component = () => {
)
}
```
[Code Sandbox demo](https://codesandbox.io/s/condescending-danilo-5yj655?file=/src/App.tsx:0-644)

**Advanced options**

Expand All @@ -90,7 +92,7 @@ const options = {
},
canvas: {
// default is 'image/jpeg' for better size performance
mimeType: 'image/png'
mimeType: 'image/png',
qualityRatio: 1
},
// Customize any value passed to the jsPDF instance and html2canvas
Expand All @@ -103,7 +105,7 @@ const options = {
},
// see https://html2canvas.hertzen.com/configuration for more options
canvas: {
useCORS: false
useCORS: true
}
},
};
Expand All @@ -122,3 +124,4 @@ const Component = () => {
);
}
```
[Code Sandbox demo](https://codesandbox.io/s/billowing-fog-lq4xj6?file=/src/App.tsx)
8 changes: 4 additions & 4 deletions docs/enums/constants.Margin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#### Defined in

[constants.ts:17](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L17)
[src/constants.ts:18](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L18)

___

Expand All @@ -31,7 +31,7 @@ ___

#### Defined in

[constants.ts:16](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L16)
[src/constants.ts:17](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L17)

___

Expand All @@ -41,7 +41,7 @@ ___

#### Defined in

[constants.ts:14](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L14)
[src/constants.ts:15](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L15)

___

Expand All @@ -51,4 +51,4 @@ ___

#### Defined in

[constants.ts:15](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L15)
[src/constants.ts:16](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L16)
10 changes: 5 additions & 5 deletions docs/enums/constants.Resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#### Defined in

[constants.ts:10](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L10)
[src/constants.ts:11](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L11)

___

Expand All @@ -32,7 +32,7 @@ ___

#### Defined in

[constants.ts:9](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L9)
[src/constants.ts:10](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L10)

___

Expand All @@ -42,7 +42,7 @@ ___

#### Defined in

[constants.ts:6](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L6)
[src/constants.ts:7](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L7)

___

Expand All @@ -52,7 +52,7 @@ ___

#### Defined in

[constants.ts:8](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L8)
[src/constants.ts:9](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L9)

___

Expand All @@ -62,4 +62,4 @@ ___

#### Defined in

[constants.ts:7](https://github.com/ivmarcos/react-to-pdf/blob/36bd08b/src/constants.ts#L7)
[src/constants.ts:8](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/constants.ts#L8)
102 changes: 102 additions & 0 deletions docs/interfaces/types.ConversionOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[react-to-pdf](../README.md) / [Modules](../modules.md) / [types](../modules/types.md) / ConversionOptions

# Interface: ConversionOptions

[types](../modules/types.md).ConversionOptions

## Table of contents

### Properties

- [canvas](types.ConversionOptions.md#canvas)
- [filename](types.ConversionOptions.md#filename)
- [method](types.ConversionOptions.md#method)
- [overrides](types.ConversionOptions.md#overrides)
- [page](types.ConversionOptions.md#page)
- [resolution](types.ConversionOptions.md#resolution)

## Properties

### canvas

• **canvas**: `CanvasConversionOptions`

Canvas options

#### Defined in

[src/types.ts:60](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L60)

___

### filename

• `Optional` **filename**: `string`

File name of the PDF file if the method select is `save`, which is the
default. Not used for the `build` and `open` methods. *

#### Defined in

[src/types.ts:42](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L42)

___

### method

• **method**: ``"open"`` \| ``"save"`` \| ``"build"``

Method that will follow to do with the PDF file. The `build` method just
returns the PDF instance in the invoked function `generatePDF` or `toPDF`.
By default is `open`.

#### Defined in

[src/types.ts:48](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L48)

___

### overrides

• **overrides**: `Object`

Override values passed for the jsPDF document and html2canvas

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `canvas?` | `Partial`<`Options`\> | Override the values passed for the html2canvas function. See its docs for more details in https://html2canvas.hertzen.com/documentation |
| `pdf?` | `Partial`<`jsPDFOptions`\> | Override the values passed for the jsPDF instance. See its docs for more details in https://artskydj.github.io/jsPDF/docs/jsPDF.html. |

#### Defined in

[src/types.ts:62](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L62)

___

### page

• **page**: `PageConversionOptions`

Page options

#### Defined in

[src/types.ts:58](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L58)

___

### resolution

• **resolution**: `number`

Resolution in a scale where 1 gives a low resolution and possible blurred
image, 3 a medium and 10 an extreme quality. The size of the file increases
as the resolution is higher. Not recommended to use extreme resolution, e.g
'>= 10' for multiple pages otherwise this can make the browser cache hang
or crash, due to the size of the image generated for the PDF.

#### Defined in

[src/types.ts:56](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L56)
107 changes: 107 additions & 0 deletions docs/interfaces/types.Options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[react-to-pdf](../README.md) / [Modules](../modules.md) / [types](../modules/types.md) / Options

# Interface: Options

[types](../modules/types.md).Options

## Hierarchy

- `Omit`<`Partial`<[`ConversionOptions`](types.ConversionOptions.md)\>, ``"page"`` \| ``"canvas"`` \| ``"overrides"``\>

↳ **`Options`**

## Table of contents

### Properties

- [canvas](types.Options.md#canvas)
- [filename](types.Options.md#filename)
- [method](types.Options.md#method)
- [overrides](types.Options.md#overrides)
- [page](types.Options.md#page)
- [resolution](types.Options.md#resolution)

## Properties

### canvas

• `Optional` **canvas**: `Partial`<`CanvasConversionOptions`\>

#### Defined in

[src/types.ts:79](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L79)

___

### filename

• `Optional` **filename**: `string`

File name of the PDF file if the method select is `save`, which is the
default. Not used for the `build` and `open` methods. *

#### Inherited from

Omit.filename

#### Defined in

[src/types.ts:42](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L42)

___

### method

• `Optional` **method**: ``"open"`` \| ``"save"`` \| ``"build"``

Method that will follow to do with the PDF file. The `build` method just
returns the PDF instance in the invoked function `generatePDF` or `toPDF`.
By default is `open`.

#### Inherited from

Omit.method

#### Defined in

[src/types.ts:48](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L48)

___

### overrides

• `Optional` **overrides**: `Partial`<{ `canvas?`: `Partial`<`Options`\> ; `pdf?`: `Partial`<`jsPDFOptions`\> }\>

#### Defined in

[src/types.ts:80](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L80)

___

### page

• `Optional` **page**: `Partial`<`PageConversionOptions`\>

#### Defined in

[src/types.ts:78](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L78)

___

### resolution

• `Optional` **resolution**: `number`

Resolution in a scale where 1 gives a low resolution and possible blurred
image, 3 a medium and 10 an extreme quality. The size of the file increases
as the resolution is higher. Not recommended to use extreme resolution, e.g
'>= 10' for multiple pages otherwise this can make the browser cache hang
or crash, due to the size of the image generated for the PDF.

#### Inherited from

Omit.resolution

#### Defined in

[src/types.ts:56](https://github.com/ivmarcos/react-to-pdf/blob/79d4272/src/types.ts#L56)
Loading