0

Has anyone set up electron to pass the PDFViewer component that is then displayed to the DOM from React? I am able to display an empty box because the blob file and html aren't passed to the DOM like it does in a simple React app. The blob file is asked to be saved somewhere instead of just being used to the DOM as the simple React app does.

I thinking the PDFViewer information needs to be passed through the package.json/webpack somehow to the electron main.dev.ts file to properly display to the DOM.

I also get a memory leak due to PDFViewer being mounted and unmounted:

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. in InternalBlobProvider (created by PDFViewer) in PDFViewer (at tearDownSummery.tsx:9) in div (at tearDownSummery.tsx:8)

This is what I have to call my pdf component I setup that works up to the point to displaying to the DOM. The download link works and I get the PDF I structured through the .

import React from 'react';
import { PDFViewer, PDFDownloadLink } from '@react-pdf/renderer';
import ReactDOM from 'react-dom';
import TearDownPDF from './tearDowSummeryPDF';


export default function TearDownSummery() {
  return (
    <div>
      <PDFViewer>
        <TearDownPDF />
      </PDFViewer>
      <PDFDownloadLink document={<TearDownPDF />} fileName="IIR.pdf">
        {({ blob, url, loading, error }) =>
          loading ? <i> Loading document...</i> : <i> Download Pdf </i>}
      </PDFDownloadLink>
    </div>
  );
}

ReactDOM.render(<TearDownSummery />, document.getElementById('root'));

Here is my GitHub project: https://github.com/staniszmatt/iir_Report.git It is all set up on the pdfSetup branch.

  • Never mind the memory leak error. Set to load the PDFViewer when that page is loaded. – Matthew Staniszewski Aug 06 '20 at 16:33
  • Ok, From what I can see, The HTML is getting to the DOM, but I am getting this error when the file tries to load: *Resource interpreted as Document but transferred with MIME type application/pdf: "blob:file:///9929b821-964c-4355-8f10-80a9dc44de3a".* Do I need to convert the file some how before trying to load it to the DOM and where would I do that? Does webpack need to have additional setup to convert and load the pdf properly? – Matthew Staniszewski Aug 06 '20 at 18:09

1 Answers1

0

Currently, Electron doesn't have the capability to use @react-pdf based off this post I found.

https://github.com/electron/electron/issues/13038

I'll have to come back to answer again if and when electron adds this capability.