diegomura / diegomura/react-pdf

Word-Level Orphan Control

Open
#2,374 0 comments 0 reactions 0 assignees View on GitHub
new feature
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

**Is your feature request related to a problem? Please describe.**
When using the React-PDF library to render paragraphs, single-word orphans (lines with only one word) can occur. This leads to unattractive formatting, especially in professional documents where aesthetic presentation is crucial. I'm always frustrated when the text breaks in such a way that it leaves a single word on a new line, disrupting the flow of reading.

React-Pdf already has the Orphan & Widow protection to ensure text is not orphaned at the bottom or the top of a new page, but this feature is limited to controlling entire lines and does not provide fine-grained control at the word level to prevent single-word orphans within lines of text.

**Describe the solution you'd like**
I would like the React-PDF library to include an orphan and widow control feature at the word level, allowing developers to specify the minimum number of words that should appear on a new line. This feature would prevent single-word orphans by ensuring that line breaks occur before a specified number of words from the end of the sentence, providing finer control over text layout.

**Describe alternatives you've considered**
Manually handling the text layout by calculating the width of a given string and breaking the text into lines is a possible workaround, but it's complex and time-consuming. It requires diving into specific font metrics and doesn't align with the simplicity that React-PDF generally offers. Having this feature integrated into the library would save developers time and ensure consistency across different projects.

**Example**
```

This sentence has many words but there should be a minimum of 2 words on any new line.

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.