question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The text layer is not rendered with same font weight and color

See original GitHub issue

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in Mozilla Firefox

Description The text layer over the canvas, I changed the opacity of being transparent to black color. I disabled the canvas layer being drawn. I can see the text layer now, but the font-weight and font color are not the same as pdf. I know that the text layer is rendered separately and doesn’t have to do anything with the canvas. So, I was wondering if we could somehow get these details for each textDiv created on the text layer? The font-weight and color should be the same at least.

Steps to reproduce Disable the canvas by adding the following lines in canvas.js.

CanvasRenderingContext2D.prototype.strokeText = () => {}; CanvasRenderingContext2D.prototype.fillText = () => {};

Additional _information

BEFORE Screen Shot 2020-09-18 at 4 26 40 PM

AFTER Screen Shot 2020-09-18 at 4 27 10 PM

Environment Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
evaneastoncommented, Oct 20, 2020

What confused me most was that I was comparing to other libraries (react-pdf-viewer and the vanilla PDF.js web viewer) and they seemed to be rendering the text perfectly. But that wasn’t really the case. They had simply provided css rules to make the text layer span color transparent. I was able to get a lot closer with some css that forces the ::selection pseudo style to inherit color: transparent. Without this extra rule, my chrome was showing white text over the selection highlight.

.react-pdf__Page__textContent  {
  color: transparent;
  opacity: 0.5;
}
.react-pdf__Page__textContent ::selection {
  background: #0000ff;
}

It seems that this should be default behavior or documented in the FAQ on the wiki.

But what noticed was that PDF.js viewer and react-pdf-viewer and the PDF.js viewer seem to using the built in renderTextLayer function from pdf.js’s src/display/text_layer.js. And the highlight background for those seems to better fit the text vertically. It’s just a tiny bit higher and looks better, in my opinion. Screen captures are below.

I’m curious should you really be halving the translateY result your using in TextLayerItem.alignTextItem? When I make this change locally, all the highlights appear nice and centered around the text.

Library Result
PDF.js web viewer image
react-pdf-viewer image
My CRA app using react-pdf image
2reactions
evaneastoncommented, Dec 21, 2020

I added PR 697.

Read more comments on GitHub >

github_iconTop Results From Across the Web

font-weight - CSS: Cascading Style Sheets - MDN Web Docs
The font-weight CSS property sets the weight (or boldness) of the font. The weights available depend on the font-family that is currently ...
Read more >
Same font except its weight seems different ... - Stack Overflow
Be sure the font is the same for all browsers. If it is the same font, then the problem has no solution using...
Read more >
Photoshop Font Rendering Changes While Working (Problem)
Everything about the following text layer are identical. Same font, color, rendering style. There's no "faux bold" applied or anything else.
Read more >
STOP Scaling Text in Photoshop! Solve The Paragraph Style ...
In this tutorial, you will learn how to use Paragraph Styles in Photoshop to speed up your workflow, and how free-transforming text ......
Read more >
Edit text layers – Figma Help Center
Not all fonts support the same OpenType features. Typeface creators have full control over which OpenType features they support. They could be popular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found