New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

image-to-pdf

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-to-pdf

A simple image to PDF converter

latest
Source
npmnpm
Version
3.0.2
Version published
Weekly downloads
9.7K
-21.51%
Maintainers
1
Weekly downloads
 
Created
Source

Welcome to image-to-pdf 👋

A simple 🖼️ to 📄 converter for NodeJS


Version

Instalation

npm install image-to-pdf

Example (CommonJS)

const { convert, sizes } = require('image-to-pdf');
const fs = require('fs')

const pages = [
    "./pages/image1.jpeg", // path to the image
    "data:image/png;base64,iVBORw...", // base64
    fs.readFileSync('./pages/image3.png') // Buffer
]
 
convert(pages, sizes.A4).pipe(fs.createWriteStream('output.pdf'))

Example (ECMAScript)

import imageToPDF, { sizes } from 'image-to-pdf';
import fs from 'fs';

let pages = fs.readdirSync('./img').map(file => `./img/${file}`);

imageToPDF(pages, sizes.A4).pipe(fs.createWriteStream('output-esm.pdf'));

Example (TypeScript)

const imageToPDF = require('image-to-pdf').default;
const fs = require('fs');

let pages: string[] = fs.readdirSync('./img').map((file: string) => `./img/${file}`);
// Alternatively you can also pass the size as a string like this:
imageToPDF(pages, 'A4').pipe(fs.createWriteStream('output-ts.pdf'));

Documentation

Accepted formats

The only accepted image formats are png and jpeg. They can be passed to the function as base64, Buffer or simply as a path to the file (see Example).

Page size

A list of all size presets in sizes can be found here. A custom size can be passed to the function simply as [x, y].

Output

The function returns a Stream (see official documentation). The easiest way to get a file is to pipe it into a WriteStream (see Example).

Keywords

pdf

FAQs

Package last updated on 09 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts