Skip to content

Commit a1b05fa

Browse files
authored
Merge pull request #14 from OnedocLabs/ffo-48-include-documentation-for-the-react-print-library-with
Ffo 48 include documentation for the react print library with
2 parents 5f6ce3a + 30e36be commit a1b05fa

13 files changed

+435
-17
lines changed

fern/docs.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ tabs:
1010
API:
1111
display-name: API Reference
1212
icon: fa-solid fa-bolt
13+
SDK:
14+
display-name: SDK Reference
15+
icon: fa-solid fa-code
1316
help:
1417
display-name: Help Center
1518
icon: fa-solid fa-question
@@ -171,24 +174,41 @@ navigation:
171174
snippets:
172175
typescript: "@fileforge/client"
173176
python: "fileforge"
177+
- tab: SDK
178+
layout:
179+
- section: Getting Started
180+
contents:
181+
- page: Getting Started
182+
path: ./pages/sdk-reference/introduction.mdx
183+
slug: sdk-reference
184+
- section: Node
185+
contents:
186+
- page: Getting Started
187+
path: ./pages/sdk-reference/node/introduction.mdx
188+
slug: node-sdk-reference
189+
- page: Error Handling
190+
path: ./pages/sdk-reference/node/errors.mdx
191+
slug: node-error-handling
192+
- page: Generate from HTML
193+
path: ./pages/sdk-reference/node/generate_from_html.mdx
194+
slug: node-generate-from-html
195+
- page: Merge
196+
path: ./pages/sdk-reference/node/merge.mdx
197+
slug: node-merge
174198
- tab: help
175199
layout:
176200
- section: HTML to PDF
177201
contents:
178-
- page: Generate a PDF
179-
path: ./pages/help_center/html_to_pdf/generate-pdf-from-html.mdx
202+
- page: Generate a PDF with react-print
203+
path: >-
204+
./pages/help_center/html_to_pdf/generate-pdf-from-html-react-print.mdx
180205
slug: generate-pdf-from-html
181206
- page: Generate a PDF with assets
182207
path: ./pages/help_center/html_to_pdf/generate-pdf-from-html-assets.mdx
183208
slug: generate-pdf-from-html-assets
184209
- page: Generate a hosted PDF
185210
path: ./pages/help_center/html_to_pdf/generate-hosted-pdf-from-html.mdx
186211
slug: generate-hosted-pdf
187-
- section: Merge PDFs
188-
contents:
189-
- page: Merge multiple PDF files into one
190-
path: ./pages/help_center/merge_pdfs/merge-multiple-pdfs.mdx
191-
slug: merge-multiple-pdf-files
192212
colors:
193213
accentPrimary: '#AD8AFF'
194214
background:

fern/pages/api-reference/authentication.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Authenticating to the FileForge API
2+
title: Authenticating to the Fileforge API
33
---
44

5-
Authenticating in the FileForge API is done using an API key. This key is used to authenticate your requests to the API. You can create an API key in the [FileForge app](https://app.onedoclabs.com).
5+
Authenticating in the Fileforge API is done using an API key. This key is used to authenticate your requests to the API. You can create an API key in the [Fileforge app](https://app.onedoclabs.com).
66

77
<Steps>
88
### Get your API key 🔑
9-
Go to the [FileForge app](https://app.onedoclabs.com) and create an API key.
9+
Go to the [Fileforge app](https://app.onedoclabs.com) and create an API key.
1010
### Add your key to the request headers
1111
Add your API key to the `Authorization` header in your requests with `X-API-Key`. You can test your key with the [status endpoint](/api-reference/api-reference/retrieve-server-status) using the playground.
1212
### You are all set! ✅
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Welcome to the FileForge API
2+
title: Welcome to the Fileforge API
33
---
44

5-
This is the official FileForge API documentation! 🧑‍💻
5+
This is the official Fileforge API documentation! 🧑‍💻
66

7-
The FileForge API is a powerful tool for building document-centric workflows. It enables developers to perform any PDF task like generation, form filling, e-signature, and more.
7+
The Fileforge API is a powerful tool for building document-centric workflows. It enables developers to perform any PDF task like generation, merging, form filling, and more.
88

99
To get started with authentication, check out the following guide:
1010

@@ -16,14 +16,18 @@ To get started with authentication, check out the following guide:
1616

1717
### Official API Clients
1818

19-
Vellum maintains official API clients for Python, Node/Typescript, and Go. We recommend using these clients to interact
19+
Fileforge maintains official API clients for Python and Node/Typescript. We recommend using these clients to interact
2020
with all stable endpoints. You can find them here:
2121

2222
<Cards>
2323
<Card
2424
title="Node/Typescript"
2525
icon="fa-brands fa-node"
26-
href="https://github.com/OnedocLabs/fileforge-node-sdk"
26+
href="/sdk-reference/node/node-sdk-reference"
27+
/>
28+
<Card
29+
title="Python"
30+
icon="fa-brands fa-python"
31+
href="/sdk-reference/python/python-sdk-reference"
2732
/>
28-
2933
</Cards>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
This documentation provides an example of how to use the FileForgeClient to generate a hosted PDF file from HTML.
2+
3+
#### Prerequisites
4+
5+
Ensure you have the following:
6+
7+
- An API key for Fileforge as FILEFORGE_API_KEY.
8+
- Node.js and npm installed.
9+
10+
#### Example Code
11+
12+
```typescript
13+
// HTML content with an embedded image
14+
const HTML = `<!DOCTYPE html>
15+
<html>
16+
<head>
17+
<title>My First Document</title>
18+
</head>
19+
<body>
20+
<h1>Hello World!</h1>
21+
</body>
22+
</html>
23+
`
24+
```
25+
26+
By setting the `documentInput.host` property to `true`, the Fileforge API will now return a url to your file.
27+
You can host your document with Fileforge for up to 7 days. You can set duration in the `documentInput.expiresAt` property.
28+
29+
```typescript
30+
import { generate_from_html, ResponseURL } from "@fileforge/client";
31+
32+
const client = new FileForgeClient({
33+
apiKey: FILEFORGE_API_KEY
34+
});
35+
36+
const documentInput = {
37+
html: HTML,
38+
fileName: 'example',
39+
test: true,
40+
host: true,
41+
// sets the document to be hosted for 24 hours from now
42+
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
43+
};
44+
45+
const pdf = await generate_from_html(
46+
client,
47+
documentInput
48+
) as ResponseURL;
49+
// console.log the url
50+
console.log(pdf.url);
51+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
This documentation provides an example of how to use the FileForgeClient to generate a PDF file from HTML with CSS, and SVG files aside.
2+
3+
#### Prerequisites
4+
5+
Ensure you have the following:
6+
7+
- An API key for Fileforge as FILEFORGE_API_KEY.
8+
- Node.js and npm installed.
9+
- The `fs` module for writing the output PDF file.
10+
11+
#### Example Code
12+
13+
For this example, we will use the following sample code for HTML, CSS and a SVG image.
14+
The css and image are referened in the HTML as `href="style.css"` and `"src="logo-black.svg"`.
15+
16+
```typescript
17+
// HTML content with an embedded image
18+
const HTML_W_IMAGE = `<!DOCTYPE html>
19+
<html>
20+
<head>
21+
<title>My First Document</title>
22+
<link href="style.css" rel="stylesheet" />
23+
</head>
24+
<body>
25+
<h1>Hello World!</h1>
26+
<img src="logo-black.svg" alt="FileForge logo" />
27+
</body>
28+
</html>
29+
`
30+
// Fileforge SVG logo
31+
const SVG_LOGO = `<svg width="179" height="46" viewBox="0 0 179 46" fill="none" xmlns="http://www.w3.org/2000/svg">
32+
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 6.93506H19.0099V16.1581H9.78689V19.4892H22.341V6.93506H32.13V39.0651H0V6.93506ZM13.1059 39.0631V29.84H22.329V26.509H9.77488V39.0631H13.1059Z" fill="black"/>
33+
<path d="M47.5743 36V21.3286H42.5875V18.1847H47.5743V14.282C47.5743 13.1979 47.8996 12.3306 48.55 11.6801C49.2005 11.0297 50.0678 10.7044 51.1519 10.7044H55.4882V13.8483H52.3444C51.6457 13.8483 51.2964 14.2097 51.2964 14.9324V18.1847H59.2826V21.3286H51.2964V36H47.5743ZM59.2826 36V18.1847H63.0046V36H59.2826ZM61.1617 15.872C60.4389 15.872 59.8246 15.6431 59.3187 15.1854C58.8369 14.7035 58.596 14.0892 58.596 13.3424C58.596 12.5715 58.8369 11.9572 59.3187 11.4994C59.8246 11.0417 60.4389 10.8128 61.1617 10.8128C61.8844 10.8128 62.4867 11.0417 62.9685 11.4994C63.4744 11.9572 63.7274 12.5715 63.7274 13.3424C63.7274 14.0892 63.4744 14.7035 62.9685 15.1854C62.4867 15.6431 61.8844 15.872 61.1617 15.872ZM66.6894 36V10.7044H70.4115V36H66.6894ZM82.2953 36.5059C80.4885 36.5059 78.9105 36.1325 77.5614 35.3857C76.2123 34.6148 75.1523 33.5427 74.3814 32.1695C73.6346 30.7722 73.2612 29.1582 73.2612 27.3272V26.8936C73.2612 25.0386 73.6346 23.4245 74.3814 22.0513C75.1283 20.654 76.1642 19.582 77.4892 18.8352C78.8383 18.0642 80.3921 17.6788 82.1508 17.6788C83.8612 17.6788 85.3549 18.0642 86.6317 18.8352C87.9326 19.582 88.9444 20.6299 89.6672 21.979C90.3899 23.3281 90.7513 24.9061 90.7513 26.7129V28.1222H77.0555C77.1037 29.6882 77.6217 30.9409 78.6094 31.8804C79.6212 32.7959 80.874 33.2536 82.3676 33.2536C83.7649 33.2536 84.8128 32.9404 85.5115 32.3141C86.2342 31.6877 86.7883 30.965 87.1738 30.1459L90.2454 31.7359C89.9081 32.4104 89.4142 33.1211 88.7638 33.8679C88.1374 34.6148 87.3063 35.2411 86.2703 35.747C85.2344 36.253 83.9094 36.5059 82.2953 36.5059ZM77.0917 25.2675H86.9569C86.8606 23.9184 86.3788 22.8704 85.5115 22.1236C84.6442 21.3527 83.5119 20.9672 82.1146 20.9672C80.7174 20.9672 79.573 21.3527 78.6817 22.1236C77.8144 22.8704 77.2844 23.9184 77.0917 25.2675ZM95.9705 36V21.3286H90.9836V18.1847H95.9705V14.282C95.9705 13.1979 96.2957 12.3306 96.9461 11.6801C97.5966 11.0297 98.4639 10.7044 99.548 10.7044H104.137V13.8483H100.74C100.042 13.8483 99.6925 14.2097 99.6925 14.9324V18.1847H104.824V21.3286H99.6925V36H95.9705ZM114.434 36.5059C112.652 36.5059 111.062 36.1445 109.664 35.4218C108.291 34.675 107.207 33.615 106.412 32.2418C105.617 30.8686 105.219 29.2425 105.219 27.3634V26.8213C105.219 24.9422 105.617 23.3281 106.412 21.979C107.207 20.6058 108.291 19.5458 109.664 18.799C111.062 18.0522 112.652 17.6788 114.434 17.6788C116.217 17.6788 117.807 18.0522 119.204 18.799C120.602 19.5458 121.698 20.6058 122.493 21.979C123.288 23.3281 123.685 24.9422 123.685 26.8213V27.3634C123.685 29.2425 123.288 30.8686 122.493 32.2418C121.698 33.615 120.602 34.675 119.204 35.4218C117.807 36.1445 116.217 36.5059 114.434 36.5059ZM114.434 33.1814C116.072 33.1814 117.397 32.6634 118.409 31.6275C119.445 30.5675 119.963 29.11 119.963 27.255V26.9297C119.963 25.0747 119.457 23.6293 118.445 22.5934C117.434 21.5333 116.097 21.0033 114.434 21.0033C112.82 21.0033 111.495 21.5333 110.459 22.5934C109.447 23.6293 108.941 25.0747 108.941 26.9297V27.255C108.941 29.11 109.447 30.5675 110.459 31.6275C111.495 32.6634 112.82 33.1814 114.434 33.1814ZM126.512 36V18.1847H130.162V20.2806H130.74C131.029 19.5338 131.487 18.9917 132.113 18.6545C132.764 18.2931 133.559 18.1124 134.498 18.1124H136.631V21.4731H134.354C133.149 21.4731 132.162 21.8104 131.391 22.4849C130.62 23.1354 130.234 24.1472 130.234 25.5204V36H126.512ZM137.178 27.1827V26.6406C137.178 24.7615 137.551 23.1595 138.298 21.8345C139.069 20.5095 140.081 19.4856 141.333 18.7629C142.586 18.0401 143.959 17.6788 145.453 17.6788C147.187 17.6788 148.512 18.004 149.428 18.6545C150.367 19.3049 151.054 20.0036 151.488 20.7504H152.066V18.1847H155.68V39.6498C155.68 40.7339 155.354 41.6012 154.704 42.2516C154.078 42.9021 153.21 43.2273 152.102 43.2273H140.105V39.975H150.946C151.644 39.975 151.994 39.6137 151.994 38.8909V33.2175H151.415C151.15 33.6511 150.777 34.0968 150.295 34.5545C149.813 35.0123 149.175 35.3857 148.38 35.6748C147.609 35.9639 146.633 36.1084 145.453 36.1084C143.959 36.1084 142.574 35.7591 141.297 35.0605C140.044 34.3377 139.045 33.3139 138.298 31.9888C137.551 30.6397 137.178 29.0377 137.178 27.1827ZM146.465 32.8561C148.079 32.8561 149.404 32.3502 150.44 31.3384C151.5 30.3025 152.03 28.8811 152.03 27.0743V26.7491C152.03 24.894 151.512 23.4727 150.476 22.4849C149.44 21.4731 148.103 20.9672 146.465 20.9672C144.875 20.9672 143.55 21.4731 142.49 22.4849C141.454 23.4727 140.936 24.894 140.936 26.7491V27.0743C140.936 28.8811 141.454 30.3025 142.49 31.3384C143.55 32.3502 144.875 32.8561 146.465 32.8561ZM167.52 36.5059C165.713 36.5059 164.135 36.1325 162.786 35.3857C161.437 34.6148 160.377 33.5427 159.606 32.1695C158.859 30.7722 158.486 29.1582 158.486 27.3272V26.8936C158.486 25.0386 158.859 23.4245 159.606 22.0513C160.353 20.654 161.388 19.582 162.713 18.8352C164.063 18.0642 165.616 17.6788 167.375 17.6788C169.086 17.6788 170.579 18.0642 171.856 18.8352C173.157 19.582 174.169 20.6299 174.891 21.979C175.614 23.3281 175.976 24.9061 175.976 26.7129V28.1222H162.28C162.328 29.6882 162.846 30.9409 163.834 31.8804C164.846 32.7959 166.098 33.2536 167.592 33.2536C168.989 33.2536 170.037 32.9404 170.736 32.3141C171.459 31.6877 172.013 30.965 172.398 30.1459L175.47 31.7359C175.132 32.4104 174.639 33.1211 173.988 33.8679C173.362 34.6148 172.531 35.2411 171.495 35.747C170.459 36.253 169.134 36.5059 167.52 36.5059ZM162.316 25.2675H172.181C172.085 23.9184 171.603 22.8704 170.736 22.1236C169.869 21.3527 168.736 20.9672 167.339 20.9672C165.942 20.9672 164.797 21.3527 163.906 22.1236C163.039 22.8704 162.509 23.9184 162.316 25.2675Z" fill="black"/>
34+
</svg>
35+
`
36+
// css
37+
const CSS =`body{
38+
background-color: lightblue;
39+
};
40+
`
41+
```
42+
43+
The HTML is rendered to PDF as shown below.
44+
The css and svg are passed to the Fileforge API in `documentInput.files`.
45+
46+
```typescript
47+
import { generate_from_html, ResponseStream } from "@fileforge/client";
48+
49+
const ff = new FileForgeClient({
50+
apiKey: FILEFORGE_API_KEY
51+
});
52+
53+
const documentInput = {
54+
html: HTML_W_IMAGE,
55+
fileName: 'example',
56+
test: true,
57+
files: [
58+
{ path: 'style.css', content: CSS },
59+
{ path: 'logo-black.svg', content: SVG_LOGO }
60+
],
61+
};
62+
63+
const pdf = await generate_from_html(
64+
ff,
65+
documentInput
66+
) as ResponseStream;
67+
68+
// Write the PDF stream to a file
69+
const writeStream = fs.createWriteStream('output_svg_helper.pdf');
70+
pdf.file.pipe(writeStream);
71+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
This documentation provides an example of how to use the FileForgeClient to generate a hosted PDF file from HTML.
2+
3+
#### Prerequisites
4+
5+
Ensure you have the following:
6+
7+
- An API key for Fileforge as FILEFORGE_API_KEY.
8+
- Node.js and npm installed.
9+
10+
#### Example Code
11+
12+
Write your react component:
13+
14+
```typescript
15+
import React from 'react';
16+
17+
// Define the HelloWorld component
18+
const HelloWorld = () => {
19+
return (
20+
<h1>Hello World!</h1>
21+
);
22+
};
23+
24+
// Export the HelloWorld component
25+
export default HelloWorld;
26+
```
27+
28+
Compile it to HTML using react-print's [compile](/react-print/components/compile/compile) function:
29+
30+
```typescript
31+
import { compile } from "@fileforge/client";
32+
import HelloWorld from "...";
33+
34+
const HTML = compile(<HelloWorld />);
35+
```
36+
37+
By setting the `documentInput.host` property to `true`, the Fileforge API will now return a url to your file.
38+
You can host your document with Fileforge for up to 7 days. You can set duration in the `documentInput.expiresAt` property.
39+
40+
```typescript
41+
import { generate_from_html, ResponseURL } from "@fileforge/client";
42+
43+
const client = new FileForgeClient({
44+
apiKey: FILEFORGE_API_KEY
45+
});
46+
47+
const documentInput = {
48+
html: HTML,
49+
fileName: 'example',
50+
test: true,
51+
host: true,
52+
};
53+
54+
const pdf = await generate_from_html(
55+
client,
56+
documentInput
57+
) as ResponseURL;
58+
// console.log the url
59+
console.log(pdf.url);
60+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Welcome to Fileforge
3+
---
4+
5+
Welcome to Fileforge's SDK documentation! Here you'll find information about the various methods available to you,
6+
as well as the parameters and responses that they accept and return. If you have any questions, feel free to reach out on Discord.
7+
8+
### Official API Clients
9+
10+
Fileforge maintains official API clients for Python, Node/Typescript. We recommend using these clients to interact
11+
with all stable endpoints. You can find them here:
12+
13+
<Cards>
14+
<Card
15+
title="Node/Typescript"
16+
icon="fa-brands fa-node"
17+
href="/sdk-reference/node/node-sdk-reference"
18+
/>
19+
<Card
20+
title="Python"
21+
icon="fa-brands fa-python"
22+
href="/sdk-reference/python/python-sdk-reference"
23+
/>
24+
</Cards>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### Error Handling in FileForge Functions
2+
3+
#### Overview
4+
5+
Error handling is a crucial aspect of any application that interacts with external APIs. The FileForge functions, such as `generate_from_html` and `merge`, are designed to throw specific errors based on different failure scenarios. Proper error handling ensures that your application can gracefully handle issues and provide meaningful feedback to users.
6+
7+
#### Common Errors
8+
9+
The FileForge functions can throw the following common errors:
10+
11+
- `FileForge.BadRequestError`
12+
- `FileForge.UnauthorizedError`
13+
- `FileForge.InternalServerError`
14+
- `FileForge.BadGatewayError`
15+
- `FileForgeTimeoutError`
16+
- `FileForgeError`

0 commit comments

Comments
 (0)