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

pdf-lib-extended

v1.0.2

Published

This project extends the capabilities of the pdf-lib JavaScript library by providing a set of helper functions that simplify common PDF manipulation tasks. It includes utilities for drawing and formatting text, images, and shapes within PDF documents, all

Downloads

195

Readme

PDF-lib-Extended

PDF-lib-Extended is a JavaScript library that extends the functionality of the popular pdf-lib library. This extension adds several useful methods for working with PDF documents, making it easier to manipulate text, images, tables, and other elements within your PDFs.

Installation

To install PDF-lib-Extended, use npm:

npm install pdf-lib-extended

Usage

Here’s a basic example of how to use PDF-lib-Extended in your project:

import PDFExtended from 'pdf-lib-extended';

async function createPDF() {
    const pdf = new PDFExtended();
    await pdf.init();

    // Add a new page
    pdf.addNewPage();

    // Draw some text
    pdf.drawText('Hello, World!', {
        align: 'center',
        size: 24,
        color: pdf.getColor(),
    });

    // Draw a circle with text inside
    pdf.drawCircleText(100, 100, 'A', {
        size: 12,
        color: pdf.getColor(),
    });

    // Generate and download the PDF
    const pdfUrl = await pdf.generatePDFURL();
    window.open(pdfUrl);
}

createPDF();

Features

PDF-lib-Extended includes several custom methods to enhance your PDF creation experience:

  • Text Handling:

    • drawText(text, options): Draws text on the current page with alignment, color, and size options.
    • drawParagraph(text, options): Automatically wraps text to the next line within specified bounds.
  • Shape Drawing:

    • drawCircleText(x, y, text, options): Draws a circle with text centered inside.
  • Tables:

    • drawTable(header, data, options): Draws a table with customizable borders, alignment, and size.
  • Images:

    • addImage(x, y, base64Image, imageScale): Adds an image to the PDF document at specified coordinates with optional scaling.
  • Watermarks:

    • drawWatermark(text, size): Draws a watermark on each page of the document.
  • Document Management:

    • addNewPage(dimensions): Adds a new page to the PDF document.
    • fetchPDF(url): Fetches an existing PDF from a URL and loads it into the document.
    • mergePDF(urls): Merges multiple PDFs from URLs into the current document.
  • HTML Parsing:

    • htmlParser(text, parser, options): Parses HTML and draws it on the PDF.

API Reference

init() Initializes the PDF document and embeds fonts.

setTextSize(number) Sets the text size for the document.

setCircleScale(number) Sets the scale for circles drawn on the document.

setMargin(arr) Sets the margins for the document.

setCurrentPage(page) Sets the current page of the document.

setColor(color) Sets the color for text and shapes.

getPDF() Returns the current PDF document instance.

generatePDFURL() Generates a URL for downloading the PDF document.

drawText(text, options) Draws text on the current page.

drawCircleText(x, y, text, options) Draws a circle with text centered inside.

drawTable(header, data, options) Draws a table with the specified header and data.

addImage(x, y, base64Image, imageScale) Adds an image to the PDF document.

drawWatermark(text, size) Draws a watermark on each page of the document.

Contributing

If you find a bug or have a feature request, feel free to open an issue or submit a pull request. Contributions are welcome!

License

This project is licensed under the MIT License.