PDF renders incorrectly if wrapped in an element with dir="rtl"
See original GitHub issueSo I’m using this module in a fairly simple way as follows (my build is standard react-create-app):
import { Document, Page } from "react-pdf";
import { pdfjs } from "react-pdf";
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
<Document
file={`${this.state.base64Url}`}
options={{
cMapUrl: `//cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs.version}/cmaps/`,
cMapPacked: true
}}
onLoadError={(err: any) => {
console.log(err);
}}
>
<Page pageNumber={1} />
</Document>
The PDF renders the text very weirdly like that:
I’m using the simple dummy pdf from: https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
I can’t figure out what’s the problem. My base64 is ok and I doubled checked it online to see it renders correctly. No matter which PDF I try, I always get this.
I don’t have any errors on my console, other than this warning:
./node_modules/pdfjs-dist/build/pdf.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Structural markup and right-to-left text in HTML - W3C
This article looks at ways of handling text direction for structural markup in HTML, ie. at the document level and for elements like ......
Read more >Why is a trailing punctuation mark rendered at the start with ...
If you don't know if page will be rendered RTL or LTR but some text is definitely LTR (i.e. English-only) you can wrap...
Read more >react-pdf/CHANGELOG and react-pdf Releases | LibHunt
Display PDFs in your React app as easily as if they were images. ... Fixed PDF rendering incorrectly if wrapped in an element...
Read more >Missing or garbled text when converting or combining PDF ...
Text is scrambled, garbled, or displays as "garbage" characters. Some text appears in subscript. Text prints incorrectly. Solution: Embed fonts ...
Read more >Right-to-left Styling - RTL Styling 101
When dir="rtl is set on the element, the title is much clearer. ... However, when the content is Arabic, it causes a weird...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ok found it, seems like <body dir=“rtl” is causing the funky render. you can see the problem here: https://codesandbox.io/s/react-pdf-dummy-pdf-zwo0h?file=/index.html fixed it on my end, by removing ‘dir=“rtl”’ from the the document viewer (not necessary). @wojtekmaj i might consider fixing the package
Note: This fix was cherry-picked to v4.2.0 release.