Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to overwrite library method #219

Open
mandys opened this issue Nov 12, 2020 · 1 comment
Open

How to overwrite library method #219

mandys opened this issue Nov 12, 2020 · 1 comment

Comments

@mandys
Copy link

mandys commented Nov 12, 2020

Hi,

I am using the getRawTextContent() method.

let pdfParser = new PDFParser(this, 1);
pdfParser.setPassword(mypassword);
pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError));
pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile("parsed.txt", pdfParser.getRawTextContent(), () => {

});

Now, if I use the one provided by library, the words in my line don't have proper spacing.
However, if I alter the method, it works fine.

eg:

From pdf.js

If I just change

prevText.str += textObj.str;

to

prevText.str += textObj.str + " ";

All my code works fine.

But, I want to know the best way to override this function in my code.

cls.prototype.getRawTextContent = function() {
    let retVal = "";
    if (!this.needRawText)
        return retVal;

    _.each(this.rawTextContents, function(textContent, index) {
        let prevText = null;
        _.each(textContent.bidiTexts, function(textObj, idx) {
            if (prevText) {
	            if (Math.abs(textObj.y - prevText.y) <= 9) {
		            **prevText.str += textObj.str;**
	            }
	            else {
		            retVal += prevText.str  + "\r\n";
		            prevText = textObj;
	            }
            }
            else {
	            prevText = textObj;
            }

        });
        if (prevText) {
	        retVal += prevText.str;
        }
        retVal += "\r\n----------------Page (" + index + ") Break----------------\r\n";
    });

    return retVal;
};
@NatanB4
Copy link

NatanB4 commented Nov 17, 2022

I have a very similar problem, did you manage to solve yours? @mandys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants