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

@gquagliano/jspdf-textbox

v1.3.0

Published

Rich text boxes for jsPDF.

Downloads

21

Readme

jsPDF TextBox

Rich text boxes for jsPDF.

This library lets you:

  • Add rich text to your jsPDF documents, using a syntax similar to Markdown.
  • Create text boxes with horizontal/vertical overflow control, and page breaks.
  • Compute text boxes dimensions, useful to arrange other document elements relative to the text (like backgrounds).

Usage

Install

npm i @gquagliano/jspdf-textbox

Usage

import  jsPDF  from  "jspdf";
import textBox from "@gquagliano/jspdf-textbox";

let doc = new jsPDF();

let myTextBox = new textBox(doc, "**Hello** World", {
	//options
});

//In case you need the text box dimensions before actually drawing it:
//myTextBox.pages - Number of pages used up by the text box
//myTextBox.finalY - Final Y position (last page)
//myTextBox.finalHeight - Height of the text box (last page)

myTextBox.draw();

Supported formats

  • **bold**
  • *italic*
  • ***bold italic***
  • _underlined_
  • # Heading 1 (block)
  • ## Heading 2 (block)
  • > Centered paragraph (block)
  • >> Right-aligned paragraph (block)
  • <> Justified paragraph (block)
  • Fill with spaces in between (four spaces, only if the box/block is justified)
  • < Left-aligned paragraph (block)
  • ^ Small text (block)
  • Escape character: \

Note: "block" means that the token formats whole lines (until line break or end of input), and it must be located at the begining of the line.

Note: You can use one single escape character in front of a string of all the same character, for example: \_______ will print the entire line _______ instead of escaping just the first underscore.

Options

|Option|Description|Default value| |--|--|--| |startY|Initial Y position.|Top margin.| |margin|Page margins as a number (all margins will be equal), or as an object {top, bottom, left, right}|0| |width|Width of the text box|Page width minus margins.| |baseline|Baseline option for the jsPDF text() function (see jsPDF docs)|top| |numLines|Limit the number of lines to be drawn.|| |maxHeight|Maximum height. This will disable page breaks even if the value is greater than the available space in the page.|| |ellipsis|Wether or not to add ellipsis if the text overflows the box.|false| |lineBreak|false, lines won't break unless a \n is found.|true| |pageBreak|Wether or not to add new pages if necessary.|true| |textAlign|Text align, as "left", "right", "center", "justify", "justify-right" or "justify-center".|left| |styles|Styles for the different elements. See below.||

Styles

Only a couple of styles are supported so far.

|Property|Description|Default| |--|--|--| |h1|Heading 1|bold = true, fontSize 175% of default text size| |h2|Heading 2|bold = true, fontSize 145% of default text size| |p|Default text style|| |small|Default small text style|fontSize 85% of default text size|

Supported styles:

  • fontSize
  • bold (boolean)
  • italic (boolean)
  • underline (boolean)
  • marginBottom
  • lineHeight (line height factor)

Note: Paragraph style will be the document's text style at the moment of drawing. Font face, size and leading should not change between the textBox instance creation and the execution of draw().

Note: Styles reset for each block/paragraph.

TODO

  1. Add more formatting tokens, including colors, links and images--or full Markdown support.
  2. Add validations & friendly error messages.
  3. Columns.
  4. Hyphenate.
  5. Position the box relative to the bottom margin of the page.
  6. Test! The current version is a work in progress, use it at your own risk.