Giter Site home page Giter Site logo

web-dev-collaborative / pdf-actions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from manasmadan/pdf-actions

0.0 0.0 0.0 12 KB

A NPM Package built on top of pdf-lib that provides functonalities like merge, rotate, split,download pdf to disk and many more...

Home Page: https://pdfactions.vercel.app/

License: MIT License

JavaScript 100.00%

pdf-actions's Introduction

Create and modify PDF documents in any JavaScript environment.
Designed to work in any modern JavaScript runtime. Tested in Node, Browser, Deno, and React Native environments.


Table of Contents

Features

  • Modify existing PDFs
  • Merge PDFs
  • Rotate PDFs
  • Split PDFs
  • Download PDFs
  • Create ZIP File Of PDFs Processed

Usage Examples

Merge PDFs

// Importing The Required Modules
import { createPDF,pdfArrayToBlob, mergePDF } from "pdf-actions";

// Async Function To Merge PDF Files Uploaded Using The Input Tag in HTML
const mergePDFHandler = async (files) => {
  // Converting File Object Array To PDF Document Array
  files.forEach((file)=>await createPDF.PDFDocumentFromFile(file))
  // Merging The PDF Files to A PDFDocument
  const mergedPDFDocument = await mergePDF(files)
  // Converting The Merged Document to Unit8Array
  const mergedPdfFile = await mergedPDFDocument.save();
  // Saving The File To Disk
  const pdfBlob = pdfArrayToBlob(mergedPdfFile);
};

Rotate PDFs

// Importing The Required Modules
import { createPDF, rotatePDF, zipToBlob } from "pdf-actions";

// Async Function To Rotate PDF Files Uploaded Using The Input Tag in HTML
const rotatePDFHandler = async (files) => {
  // Creating A JSZip Instance 
  const zip = new JSZip();
  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const pdfDoc = await createPDF.PDFDocumentFromFile(file);
    const rotatedPDF = await rotatePDF(pdfDoc, file.degrees); // file.degrees is not by default
    zip.file(
      `rotated-${file.name}`,
      await rotatedPDF.save() // Converting To Unit8Array
    );
  }
  const zipBlob = await zipToBlob(zip);
};

Split PDFs

// Importing The Required Modules
import { createPDF, splitPDF } from "pdf-actions";
import JSZip from "jszip";

// Async Function To Split PDF Files Uploaded Using The Input Tag in HTML
const splitPDFHandler = async (files) => {
  // Creating A JSZip Instance 
  const zip = new JSZip();
  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const pdfFile = await createPDF.PDFDocumentFromFile(file);
    // Optional degree argument Default : 0
    const splitPDF = await splitPDF(pdfFile, file.range, {
        degree: file.degrees,
    }
    const pdfFile = await splitPDF.save();
    zip.file(`split-${file.name}`, pdfFile);
  }
  await zip.generateAsync({ type: "blob" }).then(function (content) {
    saveAs(content, "splitPDFFiles.zip");
  });
};

File To Array

import { pdfArray } from "pdf-actions";

const fileArray = pdfArray(file);

Pdf Array To Blob

import { pdfArrayToBlob } from "pdf-actions";

const fileBlob = pdfArrayToBlob(fileArray);

Zip To Blob

import { zipToBlob } from "pdf-actions";

const zipBlob = zipToBlob(zipObject : JSZip Instance);

Installation

NPM Module

To install the latest stable version:

  • With npm
npm install --save pdf-actions
  • With yarn
yarn add pdf-actions

This assumes you're using npm or yarn as your package manager.

Documentation

The repo for the project site (and generated documentation files) is located here: https://github.com/ManasMadan/pdf-actions

License

MIT

pdf-actions's People

Contributors

manasmadan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.