react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Word break with numeric sequence is ignored by react-pdf rendering

Open HallexCosta opened this issue 1 year ago • 2 comments

Describe the bug I using the same component with the same styling, but when I use letters [a-zA-Z] it respects the break line due to lack of space, but when I use numbers [0-1] it does not respect the width of View

To Reproduce


  1. Create component and render
const styles = StyleSheet.create({
    body: {
        paddingTop: 35,
        paddingBottom: 65,
        paddingHorizontal: 35,
    },
    textContainer: { 
        width: 200, 
        height: 100, 
        border: '1px solid red' 
    },
    container: { 
        flex: 1, 
        display: 'flex', 
        gap: 10 
    }
});

const MyDocument = () => (
    <Document>
        <Page style={styles.body}>
            <View style={styles.container}>
                <View style={styles.textContainer}>
                    <Text>TestingTestingTestingTestingTestingTestingTestingTestingTesting</Text>
                </View>
                <View style={styles.textContainer}>
                    <Text>10101010101010101010101010101010101010</Text>
                </View>
            </View>
        </Page>
    </Document>
);


// To render the document
ReactPDF.render(<MyDocument />);

Snippet of code

Expected behavior I hope that the word-break of the View width spacing is respected, as happens when I use letters instead of numbers. Is there any way around this?

Screenshots image image

Example in CSS3

In CSS3 exist the property word-break to workaround this behavior image

Desktop

  • OS: Ubuntu 22.04.5 LTS
  • Browser: chrome
  • React-pdf version: v4.1.6

HallexCosta avatar Jan 16 '25 03:01 HallexCosta

Same issue here,

yashkolambekar avatar Jul 21 '25 05:07 yashkolambekar

Till this issue is not fixed, we can use this method, it produces similar results

<Text>
     {"yourverylongnumberstring".split("").map((line, index) => (
         <Text key={index}>{line}</Text>
     ))}
</Text>

Result:

Image

yashkolambekar avatar Jul 21 '25 05:07 yashkolambekar