v0.3.1 - Text Layout Features: Ellipsis and Paragraph Gap
π¨ 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!