关于javascript:node.js如何使用网址作为pdf路径来使用pdf2json

node.js How to use a url as pdf-path to work with pdf2json

我正在使用node.js和pdf2json解析器来解析pdf文件。
目前,它正在处理本地pdf文件。
但是我正在尝试通过node.js的URL / HTTP模块获取pdf文件,我想打开此文件进行解析。

有可能解析/处理在线pdf吗?

1
2
3
4
let query   = url.parse(req.url, true).query;
let pdfLink = query.pdf;
...
pdfParser.loadPDF(pdfLink +"");

因此,应通过以下网址提供该网址:https:// localhost:8080 /?pdf = http://whale-cms.de/pdf.pdf

有什么方法可以在在线pdf /链接中对其进行解析?

提前致谢。


我只是遇到了同样的问题,并找到了解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
        var request = require('request');
        var PDFParser = require("pdf2json");
        var pdfUrl ="http://localhost:3000/cdn/storage/PDFFiles/sk87bAfiXxPre428b/original/sk87bAfiXxPre428b"
        var pdfParser = new PDFParser();

        var pdfPipe = request({url: pdfUrl, encoding:null}).pipe(pdfParser);

        pdfPipe.on("pdfParser_dataError", err => console.error(err) );
        pdfPipe.on("pdfParser_dataReady", pdf => {
          let usedFieldsInTheDocument = pdfParser.getAllFieldsTypes();
            console.log(usedFieldsInTheDocument)
        });

资料来源:
https://github.com/modesty/pdf2json/issues/65
干杯