1

Hey I have question related transfer some of the old .hta application to chrome. Are there any replacement function in Chrome, I can parse a pdf file from the pdf file links: my old java-scripts was:

    var PDFDoc = new ActiveXObject("AcroExch.AVDoc");
    if (PDFDoc.Open(filePath, "")) {
        //PDFDoc.BringToFront;
        //PDFApp.Show();
    }
    else { 
        alert("Invalid file path for opening a PDF");
        return false;
    }
    var PDDoc = PDFDoc.GetPDDoc();
    var jso = PDDoc.GetJSObject();
    var extractor = function (fieldName) { 
        if (jso.getField(fieldName) != null) {return jso.getField(fieldName).Value;} else {return "";}
    };
    return extractor;
user1830108
  • 195
  • 1
  • 15
  • Sure there are. Google "parse pdf in javascript in browser" –  Jun 20 '18 at 14:30
  • https://mozilla.github.io/pdf.js/web/viewer.html – Keith Jun 20 '18 at 14:31
  • @Keith: pdf.js seems only to support rendering a pdf, not parsing fields – Greg Jun 20 '18 at 14:42
  • The project pdf2json for node.js seems promising: https://github.com/modesty/pdf2json – Greg Jun 20 '18 at 14:44
  • @Greg From the website -> `A general-purpose, web standards-based platform for parsing and rendering PDFs.` Note the word `parsing`, The main issue I see though, is the docs suck. :) – Keith Jun 20 '18 at 14:46
  • @Keith True, couldn't find anything useful in the documentation. This answer shows a way to parse text. Not sure if you'll get field names with it though. see: https://stackoverflow.com/questions/40635979/how-to-correctly-extract-text-from-a-pdf-using-pdf-js – Greg Jun 20 '18 at 15:05
  • @Greg Like I say, doc's are not great, but here is an example of using forms -. https://github.com/mainegreen/pdf.js/tree/master/examples/forms Just noticed it's a fork of pdf.js so something to take into account. PS. I've personally not use pdf.js, but it is a client side parser,. – Keith Jun 20 '18 at 15:38

1 Answers1

1

As suggested by @Keith take a look at the following example: https://github.com/mainegreen/pdf.js/tree/master/examples/forms

You will have to modify the index.html to make it work. Add this at the bottom of the page:

    ...
    </div>
    <div id="showHere"></div>
</div>
<script>FormsDemo.loadPdf('showHere', 'f1040.pdf');</script>
</body>

This will load and render the demo PDF. Press "show me all the data!" to display a list of all form elements. You can enter values into the PDF and these will be reflected in the list of elements.

Greg
  • 1,076
  • 1
  • 9
  • 17