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

pdfium.js

v0.2.1-rc.1

Published

A PDFium wrapper library for browser-side JavaScript

Downloads

464

Readme

A PDFium wrapper library for browser-side JavaScript

CI Status NPM Version PDFium Version License

Introduction

PDFium is a high performance open source PDF library used in chromium. However, its implementation in C/C++ makes it challenging to use in web development. PDFium.js provides a pre-built WebAssembly version of the PDFium binary and offers an interface that allows it to be used in JavaScript. It will be helpful when developing PDF-related features.

Getting Started

Installation

yarn add pdfium.js
npm install --save pdfium.js

Usage

[!NOTE] When you call PDFium(), this library will load and instantiate PDFium binary in browser environment. If your project is using SSR, such as Next.js, it should not be loaded in server-side environment. "use client"; directive might be required.

import { PDFium } from "pdfium.js";

PDFium().then((PDFiumModule) => {
  // library initialization
  PDFiumModule._FPDF_InitLibrary();

  // memory allocation
  const byteArray: Uint8Array = <FILE BINARY DATA>;
  const fileSize = byteArray.length;
  const binaryAddress = PDFiumModule.asm.malloc(fileSize);
  PDFiumModule.HEAPU8.set(byteArray, binaryAddress);

  // document loading
  const documentAddress = PDFiumModule._FPDF_LoadMemDocument(binaryAddress, fileSize, "");
});

WASM Memory Management

Here is simple code snippets about memory management.

The WASM Memory can be found in PDFiumModule.FPDF.HEAP* properties.

import { PDFium, memory } from "pdfium.js";

// options parameter can be skipped after the module loaded
PDFium().then((PDFiumModule) => {
  const nBytes = 1024;

  // allocate 1024 bytes in wasm memory
  const memoryAddress = PDFiumModule.wasmExports.malloc(nBytes);

  // you can also use calloc() to allocate 1024 bytes (array of 256 integers)
  const memoryAddress2 = memory.calloc(256, 4);

  // zero-fill allocated memory
  memory.fill(PDFiumModule.FPDF.HEAPU8, memoryAddress, nBytes);

  // free memory
  PDFiumModule.wasmExports.free(memoryAddress);
});

PDFium API

This library doesn't provide full PDFium API yet. Check full version of defined PDFium API type list here.

You can also find original API specification here.

Supported API List

  • _FPDF_InitLibrary
  • _FPDF_InitLibraryWithConfig
  • _FPDF_DestroyLibrary
  • _FPDF_GetLastError
  • _FPDF_LoadDocument
  • _FPDF_LoadMemDocument
  • _FPDF_CloseDocument
  • _FPDF_GetPageCount
  • _FPDF_LoadPage
  • _FPDF_GetPageWidth
  • _FPDF_GetPageHeight
  • _FPDF_GetPageWidthF
  • _FPDF_GetPageHeightF
  • _FPDF_GetPageSizeByIndex
  • _FPDF_ClosePage
  • _FPDFPage_CountObjects
  • _FPDFPage_GetObject
  • _FPDFPage_GenerateContent
  • _FPDFPageObj_Destroy
  • _FPDFText_LoadPage
  • _FPDFText_CountChars
  • _FPDFText_GetCharBox
  • _FPDFText_ClosePage
  • _FPDFBitmap_Create
  • _FPDFBitmap_CreateEx
  • _FPDFBitmap_FillRect
  • _FPDF_RenderPageBitmap
  • _FPDFBitmap_Destroy
  • _FPDF_DeviceToPage
  • _FPDF_PageToDevice

Author

  • Jaewook Ahn

License

This project is licensed under the MIT License.