0

Idea is to print pdf documents that I am dislaying in pdfviewer component that I have created. I am getting Uint8Array from the server and that is rendered inside component. All works, so good so far.

Problem starts with implementing printing functionality inside my pdf viewer. I am rendering pdf with react-pdf library as 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>
  );
};

When "handlePrint" triggers I am getting dialog box, but it seems not to be able to render svg.

enter image description here

Question: Is there a way to render this SVG properly, as text inside print box?

Mladen Milosavljevic
  • 1,720
  • 1
  • 12
  • 23

1 Answers1

0

Solution: As usual, after few days of struggling and just after posting question on SO, brain starts to function and I came with solution.

Rendering pdf as canvas instead of SVG solves the problem, and pdf prints out as intended.

Ty. Cheers

Mladen Milosavljevic
  • 1,720
  • 1
  • 12
  • 23