Skip to content

v0.3.1 - Text Layout Features: Ellipsis and Paragraph Gap

Choose a tag to compare

@irenteria0617 irenteria0617 released this 03 Dec 02:57
· 9 commits to main since this release

🎨 PDFStudio v0.3.1 - Advanced Text Layout Features

Two powerful new text formatting features for professional PDF layouts.

✨ New Features

1. Ellipsis - Text Truncation

Automatically truncate text that exceeds available height with customizable ellipsis.

// Default ellipsis "..."
doc.text(longText, {
  x: 50, y: 500,
  width: 200,
  height: 60,
  ellipsis: true
})

// Custom ellipsis
doc.text(article.preview, {
  x: 50, y: 500,
  width: 400,
  height: 80,
  ellipsis: '...[Read More]'
})

Features:
- βœ… Efficient O(log n) binary search algorithm
- βœ… Support for custom ellipsis strings
- βœ… Perfect for previews, summaries, and fixed-size boxes
- βœ… Works with multi-column layouts and text alignment

2. Paragraph Gap - Precise Spacing

Add exact spacing after paragraphs for professional typography.

doc.text('Section Heading', {
  x: 50,
  y: 700,
  fontSize: 16,
  font: 'Helvetica-Bold',
  paragraphGap: 20  // 20pt space after
})

doc.text('Body paragraph', {
  x: 50,
  y: doc.getCurrentY(),
  width: 500,
  fontSize: 11,
  paragraphGap: 12  // 12pt space after
})

Common values:
- 6-8pt: Tight spacing (lists, dense content)
- 10-12pt: Normal spacing (body paragraphs)
- 15-20pt: Section breaks (headings to content)

πŸ“¦ Installation

npm install @pdfstudio/pdfstudio@0.3.1

πŸ§ͺ Testing

- βœ… 229 tests passing (100% success rate)
- βœ… 21 integration tests for ellipsis and paragraphGap
- βœ… 26 unit tests for TextMeasure truncation

πŸ“š Examples

New example files demonstrating features:
- examples/test-ellipsis-paragraphgap.ts - Visual test suite (5 tests)
- examples/example-product-catalog.ts - Product cards with truncated descriptions
- examples/example-article-preview.ts - Newsletter with article previews
- examples/example-documentation.ts - Professional documentation layout

Browser demos:
- 3 interactive demos in examples/browser/index.html

πŸ”§ Implementation Details

Core changes:
- src/core/PDFWriter.ts - Ellipsis and paragraphGap implementation
- src/text/TextMeasure.ts - Binary search truncation algorithm with O(log n) complexity
- Full TypeScript type definitions for new options

Browser bundle:
- Size: 604.4kb (minified)
- Debug version: 1.3mb

πŸ“– Documentation

- README.md - Updated with feature examples
- CHANGELOG.md - Complete v0.3.1 changelog
- BROWSER.md - Browser compatibility guide

πŸ”— Links

- πŸ“¦ https://www.npmjs.com/package/@pdfstudio/pdfstudio
- 🌐 https://pdfstudio.io
- πŸ“š README.md

πŸ™ Contributors

Thanks to all contributors who made this release possible!