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

@pdf-lib/fontkit

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pdf-lib/fontkit

An advanced font engine for Node and the browser

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @pdf-lib/fontkit?

@pdf-lib/fontkit is an npm package that provides advanced font handling capabilities for the PDF-Lib library. It allows you to embed custom fonts, measure text, and perform other font-related operations when working with PDFs.

What are @pdf-lib/fontkit's main functionalities?

Embed Custom Fonts

This feature allows you to embed custom fonts into your PDF documents. The code sample demonstrates how to register the fontkit, read a custom font file, embed it into a PDF document, and use it to draw text on a page.

const { PDFDocument } = require('pdf-lib');
const fontkit = require('@pdf-lib/fontkit');
const fs = require('fs');

(async () => {
  const pdfDoc = await PDFDocument.create();
  pdfDoc.registerFontkit(fontkit);
  const fontBytes = fs.readFileSync('path/to/your/font.ttf');
  const customFont = await pdfDoc.embedFont(fontBytes);
  const page = pdfDoc.addPage();
  page.drawText('Hello, world!', { font: customFont, x: 50, y: 700, size: 30 });
  const pdfBytes = await pdfDoc.save();
  fs.writeFileSync('output.pdf', pdfBytes);
})();

Measure Text

This feature allows you to measure the width of a given text string when rendered with a specific font and size. The code sample demonstrates how to calculate the width of the text 'Hello, world!' using a custom font.

const { PDFDocument } = require('pdf-lib');
const fontkit = require('@pdf-lib/fontkit');
const fs = require('fs');

(async () => {
  const pdfDoc = await PDFDocument.create();
  pdfDoc.registerFontkit(fontkit);
  const fontBytes = fs.readFileSync('path/to/your/font.ttf');
  const customFont = await pdfDoc.embedFont(fontBytes);
  const text = 'Hello, world!';
  const textWidth = customFont.widthOfTextAtSize(text, 30);
  console.log(`Text width: ${textWidth}`);
})();

Other packages similar to @pdf-lib/fontkit

Keywords

FAQs

Package last updated on 28 Nov 2020

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