Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-images-to-pdf

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-images-to-pdf

Easily generate PDF files from images in React Native.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-native-images-to-pdf

badge

Easily generate PDF files from images in React Native.

iOSAndroid

Installation

npm install react-native-images-to-pdf

or

yarn add react-native-images-to-pdf

iOS

Run pod install in the ios directory.

Usage

Example using react-native-blob-util

import { createPdf } from 'react-native-images-to-pdf';
import RNBlobUtil from 'react-native-blob-util';

const options = {
  pages: [
    { imagePath: '/path/to/image1.jpg' },
    { imagePath: '/path/to/image2.jpg' }
  ],
  outputPath: `file://${RNBlobUtil.fs.dirs.DocumentDir}/file.pdf`,
};

createPdf(options)
  .then((path) => console.log(`PDF created successfully: ${path}`))
  .catch((error) => console.log(`Failed to create PDF: ${error}`));

This example is using react-native-blob-util to get a valid outputPath, but you can choose any other library to achieve the same functionality.

Example using react-native-document-scanner-plugin

import { createPdf } from 'react-native-images-to-pdf';
import DocumentScanner from 'react-native-document-scanner-plugin';

DocumentScanner.scanDocument()
  .then(({scannedImages}) => {
    if (!scannedImages?.length) {
      throw new Error('No images scanned');
    }

    return createPdf({
      pages: scannedImages.map(imagePath => ({ imagePath })),
      outputPath: `file:///path/to/output/file.pdf`,
    });
  })
  .then(path => console.log(`PDF created successfully: ${path}`))
  .catch(error => console.log(`Failed to create PDF: ${error}`));

API

createPdf(options: CreatePdfOptions) => Promise<string>

Returns a Promise that resolves to a string representing the output path of the generated PDF file.

CreatePdfOptions
PropertyTypeDescription
pagesPage[]Pages that should be included in the PDF.
outputPathstringThe path to the output PDF file.
Valid outputPath
UsageDescriptioniOSAndroid
file:///absolute/path/to/xxx.pdfSave PDF to local file system.

Page

PropertyTypeRequiredDefaultDescription
imagePathstringPath to the image file.
imageFitImageFit'none'Image fitting option. Possible values: 'none', 'fill', 'contain', 'cover'.
widthnumberImage widthWidth of the page in pixels.
heightnumberImage heightHeight of the page in pixels.
backgroundColorstring'white'Background color of the page.
Valid imagePath
UsageDescriptioniOSAndroid
file:///absolute/path/to/image.xxxLoad image from local file system.
data:image/xxx;base64,iVBORw...Load image from base64 string.

Example

Check the example folder for a usage demo.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

Keywords

FAQs

Package last updated on 06 Sep 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc