npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

photo-to-pdf

v1.0.1

Published

A easy to use image to PDF converter with multiple features.

Downloads

22

Readme

📸 Photo-to-PDF 📄

Welcome! 👋

Transform your images into stunning PDFs effortlessly with our feature-rich converter.


Installation

npm install photo-to-pdf
# OR
yarn add photo-to-pdf

Example

const imgToPDF = require('photo-to-pdf')
const fs = require('fs')

const pages = [
    "./pages/image1.jpeg", // path to the image
    //OR
    "data:image/png;base64,iVBORw...", // base64
    //OR
    fs.readFileSync('./pages/image3.png') // Buffer
]

const size = imgToPDF.sizes.A4;

imgToPDF(pages, size, {
    margin: 30, // Single value applied to all sides
    scale: 'fit', // Scale option set to 'fit'
    align: 'center', // Center align horizontally
    valign: 'center', // Center align vertically
    output: 'output.pdf',
    borderMargin: 10, // Margin for the border
    borderWidth: 2, // Width of the border
    pageNumbering: true, // Enable page numbering
    pageNumberFormat: '1', // Standard numerals for page numbers
    pageNumberPositionVertical: 'bottom', // Position at the bottom
    pageNumberPositionHorizontal: 'right', // Position on the right
    backgroundColor: '#f0f0f0', // Light gray background color
    filter: 'greyscale' // Apply greyscale filter
});

Documentation

Input Methods

You can provide images to the photo-to-pdf package in various formats: (You can mix up format types in one array also.)

  1. File Path: Specify the path to the image file.

    const pages = [
        "./pages/image1.jpeg",
        "./pages/image2.jpeg",
        ......
    ];
  2. Base64 String: Provide the image as a Base64 encoded string.

    const pages = [
        "data:image/png;base64,iVBORw..."
    ];
  3. Buffer: Use a Buffer containing the image data.

    const fs = require('fs');
    
    const pages = [
        fs.readFileSync('./pages/image3.png')
    ];
  4. Folder Path: Specify the path to a folder containing images. It will only select PNG and JPG images present in the folder.

    const pages = imgToPDF.getImagesFromFolder('./pages/');

Options

When using photo-to-pdf, you can customize the PDF generation with various options:

  • margin or margins: Sets the margin around the images. Accepts a single value that applies to all sides, or an object to specify custom margins for each side.

    // Single value for all sides
    margin: 30
    
    // Custom margins for each side
    margins: {
        top: 20,   
        right: 30,  
        bottom: 40, 
        left: 50    
    }
  • scale: Defines how the image should be scaled. Options include 'fit' (to fit within the page), 'fill' (to fill the page), 'none' (original size of photo) etc.

    scale: 'fit' 
  • align: Horizontal alignment of the image. Options include 'left', 'center', and 'right'.

    align: 'center' 
  • valign: Vertical alignment of the image. Options include 'top', 'center', and 'bottom'.

    valign: 'center' 
  • output: The filename for the output PDF.

    output: 'output.pdf' 
  • borderMargin: The margin around the border of the image.

    borderMargin: 10 
  • borderWidth: The width of the border.

    borderWidth: 2 
  • pageNumbering: Boolean value to enable or disable page numbering.

    pageNumbering: true 
  • pageNumberFormat: Format for page numbers (e.g., '1', 'i', 'I', 'a', 'A').

    pageNumberFormat: '1' 
  • pageNumberPositionVertical: Vertical position of the page number ('top' or 'bottom').

    pageNumberPositionVertical: 'bottom' 
  • pageNumberPositionHorizontal: Horizontal position of the page number ('left', 'center', 'right').

    pageNumberPositionHorizontal: 'right'  
  • backgroundColor: Background color of the PDF pages.

    backgroundColor: '#f0f0f0' 
  • filter: Filter to apply to the images (e.g., 'greyscale', 'sepia' , 'negative').

    filter: 'greyscale' 

Contributing

Contributions are welcome! If you'd like to contribute to photo-to-pdf, please fork the repository and submit a pull request. You can also open an issue if you have any suggestions or find any bugs.

Contact

If you have any questions or need support, feel free to contact us or open an issue on GitHub.