是否有可能让 SVG 与 react-top-print 一起工作?

问题描述

想法是打印我在我创建的 pdfviewer 组件中显示的 pdf 文档。我从服务器获取 Uint8Array 并在组件内部呈现。一切正常,到目前为止一切顺利。

问题始于在我的 pdf 查看器中实现打印功能。我正在将带有 react-pdf 库的 pdf 渲染为 SVG。

const PdfViewer = (props) => {
 // removed code that is not important for this issue

  const elmRef= useRef()

 // removed code that is not important for this issue


  const handlePrint = useReactToPrint({
    content: () => elmRef.current
  });
  //const handlePrint = useReactToPrint({ 

  return (
     <Dialog className="dialogBox" title={props.dataItem[props.field]} onClose={props.modalAction} height={'95vh'} width={'90vw'}  onClose={props.onClose}>
      <PdfDocumentControls

        handlePrint={handlePrint}

      />

      <BasePdfViewer className='pdfViewer' pageNumber={pageNumber} file={file} onDocumentLoadSuccess={onDocumentLoadSuccess} zoom={zoom} refElm={elmRef} />
       {props.children}

    </Dialog>
  );
};

当“handlePrint”触发时,我收到对话框,但似乎无法渲染 svg。

enter image description here

问题:有没有办法将这个 SVG 正确渲染为打印框内的文本?

解决方法

解决方案:像往常一样,经过几天的挣扎,刚刚在 SO 上发布问题后,大脑开始运作,我想出了解决方案。

将 pdf 渲染为画布而不是 SVG 可以解决问题,并且 pdf 会按预期打印出来。

泰。干杯

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...