NPM react-to-print无法渲染文本。

huangapple go评论70阅读模式
英文:

NPM react-to-print fails to render text

问题

我正在为我的网站添加打印当前页面的支持。我的网站是使用React Js构建的。我正在使用"react-to-print",这是一个NPM模块,用于打印当前页面。我正在按照这个页面上的说明操作。我注意到一个间歇性的问题,即文字未被打印。看起来像这样:

NPM react-to-print无法渲染文本。

这是我调用React-to-print UI组件的方式:

<ReactToPrint
  documentTitle={title || ''}
  content={onPrint}
  onAfterPrint={onAfterPrint}
  onBeforeGetContent={onBeforePrint}
  removeAfterPrint
  copyStyles
  trigger={() => (
    <div className="pdf-button">
      <div className="pdf-trigger">
        <PictureAsPdfOutlined />
        <div className="text">PDF Download</div>
      </div>
    </div>
  )}
/>

我尝试删除"removeAfterPrint"属性以及许多不成功的调用。是否存在一些与这个库有关的问题,导致React UI组件无法正确渲染?

英文:

I am adding support to my website for printing the current page. My website is built with React Js. I am using 'react-to-print', a NPM module, to print the current page. I am following instructions from this page. I am observing an intermittent issue where the text is not printed. Looks like this:

NPM react-to-print无法渲染文本。

Here is my invocation of the React-to-print UI component:

&lt;ReactToPrint
  documentTitle={title || &#39;&#39;}
  content={onPrint}
  onAfterPrint={onAfterPrint}
  onBeforeGetContent={onBeforePrint}
  removeAfterPrint
  copyStyles
  trigger={() =&gt; (
    &lt;div className=&quot;pdf-button&quot;&gt;
      &lt;div className=&quot;pdf-trigger&quot;&gt;
        &lt;PictureAsPdfOutlined /&gt;
        &lt;div className=&quot;text&quot;&gt;PDF Download&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    )}
  /&gt;

I have tried removing the 'removeAfterPrint' property and many various invocations with no luck. Is there some issue with this library preventing the correct rendering of React UI components?

答案1

得分: 1

通过移除应用程序中使用的自定义字体的重复 @font-face 定义来解决了此问题。不确定究竟是什么导致了问题,但我观察到,当我从控制台调用 window.print() 时,也发生了这个问题。这个问题与 react-to-print 库无关。

英文:

Solved this issue by removing duplicate @font-face definitions for a custom font used within my application. Not sure "what" exactly was breaking; I did observe, however, that this issue was also occurring when I called window.print() from the console. The issue was not related to the react-to-print library.

huangapple
  • 本文由 发表于 2023年6月2日 00:26:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383939.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定