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

Distorted text

Open Greg-Hitchon opened this issue 2 years ago • 5 comments

Before you start - checklist

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

Description

I am getting a pdf that is rendered incorrectly and looks like: image

The actual pdf looks normal.

It is not one of the overlays causing the issue (text or annotation) and when toggling back and forth between single page and multi-page views the issue resolves. It also seems dependent on the resolution or appears on some machines and not others so it is a little tricky to repro.

Steps to reproduce

Difficult to consistently reproduce.

Expected behavior

Display pdf clearly

Actual behavior

Pdf is distorted

Additional information

No response

Environment

  • Browser (if applicable):
  • React-PDF version:
  • React version:
  • Webpack version (if applicable):

Greg-Hitchon avatar Jul 14 '22 20:07 Greg-Hitchon

I am also facing the same problem

salahCoone avatar Jul 18 '22 07:07 salahCoone

I have the same problem with external pdf docs (Google Chrome). I use this versions deps:

  • react: 18.1.0
  • react-dom: 18.1.0
  • react-pdf: 5.7.2

This is my react component for use react-pdf:

import React, { useState } from 'react';
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
import { Box } from '@mui/material';
import './index.css';

const PDFViewer: React.FC<{ fileURL: string }> = ({ fileURL }) => {
  const [numPages, setNumPages] = useState(null);

  const onDocumentLoadSuccess = (args: any) => {
    setNumPages(args.numPages);
  };

  return (
    <Document
      className="document-pdf"
      file={fileURL}
      onLoadSuccess={onDocumentLoadSuccess}
    >
      {Array.from(new Array(numPages), (el, index) => (
        <Box key={`page_${index + 1}`} marginBottom="10px">
          <Page width={900} pageNumber={index + 1} />
        </Box>
      ))}
    </Document>
  );
};

export default PDFViewer;

JaviCeRodriguez avatar Jul 19 '22 13:07 JaviCeRodriguez

We also faced the same issue in our app. However if we disable Accelerated 2D canvas in chrome://flags then the preview appears nice and okay. But since this flag is on by default so user see the pixlated preview. Unless we ask them to turn off this flag. Any resoluation is appreciated. 🙏

Related issues #1015 #1010

arfanliaqat avatar Jul 20 '22 08:07 arfanliaqat

Looks like they found at least a temporary solution over on react-pdf/renderer. https://github.com/diegomura/react-pdf/issues/1890#issuecomment-1168016232

One option is to use the renderMode="svg" on the Document but the resulting fonts are not correct.

This worked for me in react-pdf: 5.7.2, and my fonts all still look correct.

michael-roberts-lwt avatar Jul 21 '22 17:07 michael-roberts-lwt

Looks like they found at least a temporary solution over on react-pdf/renderer. diegomura/react-pdf#1890 (comment)

One option is to use the renderMode="svg" on the Document but the resulting fonts are not correct.

This worked for me in react-pdf: 5.7.2, and my fonts all still look correct.

This did help the text render correctly in my case, but then any images embedded in the pdf don't render. The images just show up as the standard 'image not found' image.

mcgeld avatar Sep 08 '22 22:09 mcgeld

Looks like they found at least a temporary solution over on react-pdf/renderer. diegomura/react-pdf#1890 (comment)

One option is to use the renderMode="svg" on the Document but the resulting fonts are not correct.

This worked for me in react-pdf: 5.7.2, and my fonts all still look correct.

This did help the text render correctly in my case, but then any images embedded in the pdf don't render. The images just show up as the standard 'image not found' image.

Yeah this is the same for me...pretty funny tbh, like playing whack-a-mole with these settings. Free though so can't complain, going to investigate some paid options I guess!

Greg-Hitchon avatar Oct 14 '22 11:10 Greg-Hitchon

Can you still see this in v6? PDF.js got updated in v6 so chances are the issues you're experiencing have been resolved by now.

wojtekmaj avatar Nov 10 '22 17:11 wojtekmaj

I will test when I get a chance! However I am not sure this will be resolved...see here...i think this is the same issue and the pdf.js folks seem to just be not supporting chrome...

Greg-Hitchon avatar Nov 10 '22 18:11 Greg-Hitchon

Can you still see this in v6? PDF.js got updated in v6 so chances are the issues you're experiencing have been resolved by now.

I can confirm this is still an issue with v6.0.3

pvg8v6g avatar Dec 01 '22 17:12 pvg8v6g

Problem exists in Chrome and Edge, but problem doesn't exist when using Firefox.

1Jesper1 avatar Dec 07 '22 12:12 1Jesper1

I’ve been testing this issue on our fork of react-pdf and I get some pretty good results, at least preliminarily. The issue was only occurring on certain integrated GPUs. Namely Intel Iris Xe, Intel UHD, Nvidia T1200.

The only change I made related to this is adding alpha: false as an option to the canvas context. canvas.getContext(‘2d’, {alpha: false});

@wojtekmaj From the early testing results, this seems to fix the distorted text. Important to note that the pdfjs viewer does not have this issue and they also have alpha: false. Is there any reason react-pdf does not have this option? Would you be open to a PR for this?

MattL75 avatar Jan 06 '23 17:01 MattL75

https://github.com/mozilla/pdf.js/issues/14641#issuecomment-1376883244 Seems to be fixed by Chrome?

1Jesper1 avatar Jan 10 '23 09:01 1Jesper1

Duplicate of #1010

wojtekmaj avatar Jan 11 '23 07:01 wojtekmaj