open-index/open-npm huggingface dataset:
npm package: @pdftemplate/sdk
Description: The official SDK for the PDFTemplate API. Create beautiful PDFs with a simple, local-first API.
Author: PDFTemplate.dev
Latest version: 0.2.0

# PDFTemplate SDK

The official Node.js SDK for the PDFTemplate API. Create beautiful PDFs with a simple, local-first API.

## Installation

```bash
npm install @pdftemplate/sdk
```

## Quick Start

Create a `generate-invoice.js` file and paste the following code. Make sure to replace `'YOUR_API_KEY'` with your actual API key.

```javascript
const { generate } = require('@pdftemplate/sdk');
const path = require('path');

async function createInvoice() {
  console.log('Generating PDF...');

  try {
    await generate(
      { apiKey: 'YOUR_API_KEY' }, // <-- IMPORTANT: Replace with your key
      (doc) => {
        // Define your document here
        doc.text({ content: 'Invoice #123', fontSize: 24, fontWeight: 'bold' });
        doc.space({ height: 20 });
        doc.text({ content: 'Billed to: ACME Corp' });
        doc.space({ height: 40 });

        doc.beginRow({ backgroundColor: '#eeeeee', padding: 5 });
        doc.text({ content: 'Item', fontWeight: 'bold' });
        doc.text({ content: 'Price', fontWeight: 'bold' });
        doc.endRow();

        doc.beginRow({ padding: 5 });
        doc.text({ content: 'Pro Widget' });
        doc.text({ content: '$250.00' });
        doc.endRow();
      }
    ).toFile(path.join(__dirname, 'invoice.pdf'));

    console.log('Successfully created invoice.pdf!');
  } catch (error) {
    console.error('Failed to generate PDF:', error);
  }
}

createInvoice();
```

Then, run the script from your terminal:

```bash
node generate-invoice.js
```

A file named `invoice.pdf` will be created in the same directory.

## API

### `generate({ apiKey }, callback)`

The main function to create a document.

-   `apiKey`: Your secret API key.
-   `callback`: A function that receives a `doc` object to build your document.

Returns a controller object with the following methods:

### `.toFile(path)`

Asynchronously saves the generated PDF to a local file. Returns a `Promise`.

### `.toStream()`

Asynchronously returns the generated PDF as a Node.js `ReadableStream`. Ideal for server environments. Returns a `Promise` that resolves with the stream.

### `.toBuffer()`

Asynchronously returns the generated PDF as a `Buffer`. Returns a `Promise` that resolves with the buffer.
npm package: @pdftron/canvas-to-pdf
Description: CanvasToPDF can create vector quality PDF images using the canvas API.
Latest version: 1.0.0

# CanvasToPDF

CanvasToPDF can create vector quality PDF images using the canvas API.

## How it works

Internally, CanvasToPDF uses modified versions of canvas2pdf and PDFKit to call on actual PDF drawing methods. CanvasToPDF has several notable improvements from canvas2pdf in that it has no issues calling fill and stroke consecutively and that reading canvas properties do not lead to errors. Thus, you can create vectorized PDFs such as the one below.

<img width="450" alt="Screen Shot 2022-08-18 at 10 23 15 AM" src="https://user-images.githubusercontent.com/70789275/185456754-0e54f33e-5c88-41cb-8821-3876f1ff5c4e.png">

CanvasToPDF internally manages a mock 2d canvas context. Thus, you only need to pass a draw function calling on canvas commands and not the canvas itself.

## Dependencies

- canvas2pdf
- PDFKit
- blob-stream

## Usage

CanvasToPDF currently only supports client-side usage. You can use this library similar to the manner below.

### Sample Code for Using CanvasToPDF

```js
import canvasToPDF from "@pdftron/canvas-to-pdf";
import saveAs from "./FileSaver";

const draw = (ctx) => {
  // canvas methods
};

canvasToPDF(draw, { width: 100, height: 150 }).then((res) => {
  saveAs(res, "example.pdf", true);
});
```

The canvasToPDF function returns a blob containing vector graphics based PDF file, but since it is difficult to check that the blob has the expected images drawn you can use FileSaver to download an actual PDF as seen in the code above.

### Sample Code for Drawing Vector PDF

```js
const draw = (ctx) => {
  for (let i = 0; i < 12; i++) {
    for (let j = 0; j < 12; j++) {
      ctx.strokeStyle = `rgb(
    0,
    ${Math.floor(255 - 42.5 * i)},
    ${Math.floor(255 - 42.5 * j)})`;
      ctx.beginPath();
      ctx.arc(25 + j * 40, 25 + i * 40, 15, 0, Math.PI * 2, true);
      ctx.stroke();
    }
  }
};
```

The above code will draw multiple circles with gradient borders:

<img width="450" alt="case2" src="https://user-images.githubusercontent.com/70789275/180508978-1b147c6d-746a-4ae9-a58b-67f41dc2ee5b.png">

## License

MIT

## Notes

- Some canvas 2d context methods are not implemented yet
- Drawing line widths of less than 1 is not supported
- Currently only supports 3 default fonts: Helvetica, Courier, and Times-Roman
npm package: @pdftron/chakra-theme
Description: A shared global theme file for PDFTron entities
Author: Logan Bittner
Latest version: 1.0.2

# PDFTron Global Chakra Theme

A shared [Chakra UI](https://chakra-ui.com/) theme to be shared across various PDFTron projects.

## Basic usage

First install the package:

```
yarn add @pdftron/chakra-theme
```

Now import the theme and pass to the ChakraProvider:

```tsx
import createTheme from '@pdftron/chakra-theme';
import { ChakraProvider } from "@chakra-ui/react"

const theme = createTheme();

export default function App() {

  return (
    <ChakraProvider theme={theme}>
      <App />
    </ChakraProvider>
  )
}
```

## Options

Things like fonts and breakpoints can be configured via options.

The `createTheme` accepts an object with the following properties (all optional):

- `primaryFont` (string) the name of your primary font. Defaults to `proxima-nova`
- `secondaryFont` (string) the name of your secondary font. Defaults to `proxima-nova`
- `backupFont` (string) the font to use if the main fonts cannot be loaded. Also used for font swapping. Should be set to a system font. Defaults to `arial`
- `breakpoints` (object) Chakra breakpoints to use. Defaults to `{sm: '600px', lg: '900px'}`

## Extending the theme

The theme can be extended using the `extendTheme` function provided by Chakra.

```tsx
import { extendTheme } from "@chakra-ui/react";
import createTheme from '@pdftron/chakra-theme';

const baseTheme = createTheme();

const theme = extendTheme({
  {
    // you custom theme here
  },
  baseTheme
})
```

## Local installation / development

To run the project locally, first clone the repo:

```
git clone git@github.com:XodoDocs/pdftron-chakra-theme.git
cd pdftron-chakra-theme
```

Install dependencies:

```
yarn
```

Run the storybook:

```
yarn storybook
```