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

How to use this plugin in React project

Open maruthi-menlo opened this issue 7 years ago • 12 comments

Hi Team/@agentcooper

I want to highlight spot in PDF and also I need to find page number and coordinates of that PDF. Please anyone let me know the steps how can I use this plugin in my React project.

I don't find any steps how to use this plugin in React project.

Note: I'm able to download this code and able to run the code locally but I need to use this as a plugin in my project.

Thanks in Advance!

maruthi-menlo avatar Sep 24 '18 05:09 maruthi-menlo

You should install the package by running npm install react-pdf-highlighter --save inside your project. Then, follow the code in https://github.com/agentcooper/react-pdf-highlighter/blob/master/demo/src/App.js, but instead of importing from src change it to "react-pdf-highlighter".

agentcooper avatar Sep 24 '18 09:09 agentcooper

hollaa @agentcooper i have installed react-pdf-highlighter on my creacte-react-app project and move all code to src folder and running using react-script ... but i have this error at my console bootstrap:1 Uncaught ReferenceError: window is not defined at bootstrap:1 at bootstrap:788 please help me, how to fix this error ?

Marlendo avatar May 23 '19 04:05 Marlendo

@agentcooper @Marlendo , I am getting this same error as well. I will do more digging to resolve this.

oseme-techguy avatar Jun 14 '19 17:06 oseme-techguy

@Marlendo @oseme-techguy @agentcooper I have this error too, Do you have a solution to this problem?

meilulan avatar Aug 12 '19 02:08 meilulan

Same error here, any updates?

rrocher avatar Aug 29 '19 01:08 rrocher

Using the instructions from this ticket, I was able to solve the window is not defined error: https://github.com/webpack/webpack/issues/6642

jbham avatar Sep 19 '19 20:09 jbham

Add this option into nwb.config.js file if you have the "window is not defined" error webpack: { extra: { output: { globalObject: 'this' }, } }

vcao2279 avatar Jan 04 '20 00:01 vcao2279

Add this option into nwb.config.js file if you have the "window is not defined" error webpack: { extra: { output: { globalObject: 'this' }, } }

it doesn't work @vcao2279

LuzMariaa avatar Jan 06 '20 07:01 LuzMariaa

@LuzMariaa Did you get any error/warning?

vcao2279 avatar Jan 06 '20 16:01 vcao2279

yes. @vcao2279 when i run yarn start. Here's the error:

? Would you like to run the app on another port instead? Yes
(node:17929) UnhandledPromiseRejectionWarning: WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

configuration.output has an unknown property 'globalObject'. These properties are valid:
object { auxiliaryComment?, chunkFilename?, crossOriginLoading?, chunkLoadTimeout?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTemplate?, filename?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, library?, libraryTarget?, libraryExport?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine? }
-> Options affecting the output of the compilation. output options tell webpack how to write the compiled files to disk.
at webpack (/Users/zhaolin/Documents/pdf/react-pdf-highlighter2/node_modules/webpack/lib/webpack.js:19:9)
at devServer (/Users/zhaolin/Documents/pdf/react-pdf-highlighter2/node_modules/nwb/lib/devServer.js:39:40)
at /Users/zhaolin/Documents/pdf/react-pdf-highlighter2/node_modules/nwb/lib/webpackServer.js:123:29
at /Users/zhaolin/Documents/pdf/react-pdf-highlighter2/node_modules/nwb/lib/webpackServer.js:62:14
(node:17929) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17929) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And nwb.config.js file:

module.exports = {
type: "react-component",
babel: {
cherryPick: "lodash"
},
npm: {
esModules: false,
umd: false
},
webpack: { extra: { output: { globalObject: 'this' }, } }
};

LuzMariaa avatar Jan 07 '20 03:01 LuzMariaa

Sorry i should have mentioned that the solution i posted was for those who wants to run react-pdf-highlighter locally. If you use it on personal project configured with webpack you might have to search for what’s causing that specific error.

vcao2279 avatar Jan 07 '20 07:01 vcao2279

Now it's ok :)

LuzMariaa avatar Jan 09 '20 03:01 LuzMariaa