# pdf2mp4

> npm module that converts pdf to mp4

Latest version **1.0.0** (published 2022-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install pdf2mp4
pnpm add pdf2mp4
yarn add pdf2mp4
bun add pdf2mp4
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-06-10 |
| First published | 2022-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 75.4 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Paulius Jacinkevicius |
| Maintainers | irgipaulius |
| Keywords | pdf2mp4, converter, fast reading |

## Links

- npm: https://www.npmjs.com/package/pdf2mp4
- Repository: https://github.com/irgipaulius/pdf2mp4
- Homepage: https://github.com/irgipaulius/pdf2mp4#readme
- Issues: https://github.com/irgipaulius/pdf2mp4/issues
- npm.io page: https://npm.io/package/pdf2mp4

## Dependencies (7)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [gm](https://npm.io/package/gm.md) 1.23.1
- [path](https://npm.io/package/path.md) ^0.12.7
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [pdfjs-dist](https://npm.io/package/pdfjs-dist.md) 2.3.200
- [find-remove](https://npm.io/package/find-remove.md) 4.0.4
- [ffmpeg-stream](https://npm.io/package/ffmpeg-stream.md) 0.7.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-06-10

## README

# pdf2mp4

Module that converts pdf files to MP4 in high resolution. Can be used for fast reading applications.

Required system dependencies:

- [ImageMagick](https://www.imagemagick.org/script/download.php)
- [gm](https://www.npmjs.com/package/gm)
- [ffmpeg](https://evermeet.cx/ffmpeg/)

> multithreaded!

## Installation

```bash
npm install pdf2mp4
```

### Prerequisites

- git
- npm & node
- ImageMagick & gm
- ffmpeg

### Setup

```bash
git clone https://github.com/irgipaulius/pdf2mp4

cd pdf2mp4

npm install
```

### GraphicsMagick

Next, you must install [ImageMagick](https://www.imagemagick.org/script/download.php) and [gm](https://www.npmjs.com/package/gm) on your system:

- Official instructions: https://github.com/yakovmeister/pdf2image/blob/HEAD/docs/gm-installation.md

- **OSX**:
  - `brew install graphicsmagick`
  - `brew install gs`
  - `brew install imagemagick`
- **Windows, Linux** - _install manually:_
  - [ImageMagick](https://www.imagemagick.org/script/download.php)
  - [gm](https://www.npmjs.com/package/gm)
- **Standalone** - _install from source:_
  - https://www.imagemagick.org/script/install-source.php
  - https://www.github.com/aheckmann/gm.git

### FFMPEG

- **OSX**
  - `brew install ffmpeg`
- **Windows**
  - Download installation executables from https://evermeet.cx/ffmpeg/.
  - add `.env` with `FFMPEG_PATH=path/to/ffmpeg/executable`
- **Linux**
  - `sudo apt install ffmpeg`
- **FreeBSD**
  - `pkg install ffmpeg`

# Usage

```typescript
import { pdf2mp4, createEventLogger } from "pdf2mp4";

const e = createEventLogger(); // optional, but great for debugging

await pdf2mp4(
  {
    fileName: "sample.pdf",
    secondsPerFrame: 2.15,
    uploadDir: "./",
    outputDir: "./",
  },
  e
);
```

## Properties

| Property        | type             | default value             | description                                                                                    |
| --------------- | ---------------- | ------------------------- | ---------------------------------------------------------------------------------------------- |
| fileName        | mandatory string |                           | name of the pdf file.                                                                          |
| secondsPerFrame | optional number  |                           | either this or `framesPerSecond` must be set.                                                  |
| framesPerSecond | optional number  |                           | either this or `secondsPerFrame` must be set.                                                  |
| maxConcurrency  | optional number  | 8                         | max concurrent frames to process at the same time. Directly affects performance and stability. |
| uploadDir       | optional string  | "pdf2mp4/upload"          | path to directory where pdf files are located                                                  |
| tempDir         | optional string  | "pdf2mp4/generated/temp"  | path to directory where temporary files will be generated                                      |
| outputDir       | optional string  | "pdf2mp4/generated/video" | path to directory where generated mp4 file is placed                                           |

## Events (optional)

For example, on front-end you can implement a full-fledged processing loading animation, which is accurate to the actual process:

```typescript
const e = new EventEmitter();

e.on("start", (message, filename) => {
  console.log(message); // Converting sample.pdf...
});

e.on("benchmark_raster", (message, benchmarkSeconds) => {
  console.log(message); // `Finished rasterization in 6.9420 seconds.`
});

e.on("benchmark_render", (message, benchmarkSeconds) => {
  console.log(message); // `Finished render in 6.9420 seconds.`
});

e.on("progress_raster", (message, progress) => {
  console.log(message); // Rasterizing... 69/100
  setProgress(progress / 100); // great to use with states for react
});

e.on("progress_render", (message, progress) => {
  console.log(message); // Rendering... 69/100
  setProgress(progress / 100); // great to use with states for react
});

e.on("end", (message, videoFilename, videoDestination) => {
  console.log(message); // Finished converting sample.pdf to /usr/Johnny/.../pdf2mp4/Am83rH3ar0.mp4.
  resolve(videoDestination); // final location of the mp4 file.
});

// no need to await, result will be in the 'end' event
pdf2mp4("sample.pdf", { framesPerSecond: 0.33 }, e);
```

# Notes

This is my first ever published npm package. Submit issues to the [github repository](https://github.com/irgipaulius/pdf2mp4) for any extra features or questions.

There is also a fully developed website that uses this package at https://www.hyperreader.eu, and it's source code is [here](https://github.com/irgipaulius/hyperreader).

---
_Source: https://npm.io/package/pdf2mp4 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
