Skip to content

Commit

Permalink
fix: fix issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
simonegosetto committed Oct 30, 2024
1 parent 410b65a commit 4320bb0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pdf-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function PDF(dataBuffer, options) {
// Disable workers to avoid yet another cross-origin issue (workers need
// the URL of the script to be loaded, and dynamically loading a cross-origin
// script does not work).
// PDFJS.PDFJS.disableWorker = true;
PDFJS.disableWorker = true;
let doc = await PDFJS.getDocument({
verbosity: options.verbosityLevel ?? DEFAULT_OPTIONS.verbosityLevel,
data: new Uint8Array(dataBuffer),
Expand Down
3 changes: 2 additions & 1 deletion lib/pdf.js/v4.5.136/build/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* JavaScript code in this page
*/

const worker = require('./pdf.worker.js');

/******/
var __webpack_modules__ = ({

Expand Down Expand Up @@ -17869,7 +17871,6 @@ class PDFWorker {
if (this.#mainThreadWorkerMessageHandler) {
return this.#mainThreadWorkerMessageHandler;
}
const worker = require( /*webpackIgnore: true*/this.workerSrc);
return worker.WorkerMessageHandler;
};
return shadow(this, "_setupFakeWorkerGlobal", loader());
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pdf-parse-new",
"version": "1.3.7",
"description": "Pure javascript cross-platform module to extract text from PDFs.",
"main": "index.js",
"main": "lib\\pdf-parse.js",
"types": "index.d.ts",
"keywords": [
"pdf-parse",
Expand All @@ -27,10 +27,15 @@
"node-ensure": "^0.0.0"
},
"devDependencies": {
"mocha": "^10.4.0"
"copy-webpack-plugin": "^12.0.2",
"mocha": "^10.4.0",
"node-loader": "^2.0.0",
"webpack": "5.94.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
"test": "node node_modules/mocha/bin/_mocha --recursive --slow 10000",
"build:test": "webpack --config ./test/webpack.config.js && node .\\test\\build.js",
"start": "node index.js",
"up:patch": "npm version patch",
"up:minor": "npm version minor",
Expand Down
2 changes: 2 additions & 0 deletions test/build.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions test/build.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* JavaScript code in this page
*/
40 changes: 40 additions & 0 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require("path");
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
mode: 'production',
target: 'node',
node: {
__dirname: false,
__filename: false,
},
module: {
rules: [
{
test: /\.node$/,
loader: "node-loader",
},
],
},
entry: './QUICKSTART.js',
output: {
path: path.resolve(process.cwd(), `test`),
filename: 'build.js',
// clean: true,
},
resolve: {
alias: {
'pdf.worker.js': path.resolve(process.cwd(), `lib\\pdf.js\\v4.5.136\\build\\pdf.worker.js`)
}
},
/*plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(process.cwd(), `lib\\pdf.js\\v4.5.136\\build\\pdf.worker.js`),
to: path.resolve(process.cwd(), `test`),
},
],
}),
],*/
}

0 comments on commit 4320bb0

Please sign in to comment.