JS PDF 到 TXT 特殊考试



我需要用javascript或php将PDF文件转换为TXT。这是我的原始文件:http://www.songmanage.com/du-bist-alles-c.pdf

我希望它在 TXT 中看起来像:

Du bist alles
Tonart - C
Text und Musik: Simon Reger
Vers 1
C                      G                            a
1. Viele Wege gibt es hier, ich kann sie alle ausprobiern
                       F
doch nur einer führt zu dir, zum Leben.
C                     G                          a
Was hab ich noch zu verliern, ohne dich bin ich verlorn
                         F
hab das schon längst eingesehn
...

有人知道如何实现这一点吗?

此文本仅作为大纲出现在 PDF 文件中,正如其他用户在上面评论的那样,需要 OCR 解决方案。如果你对 Node 感到满意.js这里有一些代码可以做到这一点。这取决于 http://www.ocrwebservice.com/API,这至少会给你一个免费的许可证代码。

索引.js

var rp = require('request-promise');
var fs = require('fs');
var args = process.argv.slice(2);
if (args.length < 3) {
    console.log('Please call like so: node index.js file username licenseCode');
    return -1;
}
var fileName = args[0];
var username = args[1];
var licenseCode = args[2];
var fileData = fs.readFileSync(fileName);
console.log('Performing OCR on: Filename: ' + fileName + " Length: " + fileData.length);
var authKey = 'Basic ' + (Buffer.from(username + ":" + licenseCode).toString('base64'));
var options = {
    method: 'POST',
    uri: 'http://www.ocrwebservice.com/restservices/processDocument?language=german&pagerange=1&outputformat=txt&gettext=true',
    body: fileData,
    headers: {
        'User-Agent': 'Request-Promise',
        'Authorization': authKey
    },
    json: false
};
rp(options)
    .then(function (parsedBody) {
        console.log('Success: ', parsedBody);
    })
    .catch(function (err) {
        console.error('Error: ', err);
    });

您可以像这样调用脚本: 节点索引.js pdf文件用户名许可证代码。

这将给出如下响应:

{
    "ErrorMessage": "",
    "OutputInformation": null,
    "AvailablePages": 22,
    "ProcessedPages": 1,
    "OCRText": [["Du bist alles Text and Musik: Simon Reger Vers 1 C G Am Viele Wege gibt es hier ich kann sie alle auspro - biern F Doch nur einer fiihrt zu dir zum Leben C G Am Was hab ich noch zu ver- liem ohne dich bin ich ver- lorn F Hab das schon !angst einge - sehn Am G F Darum lauf ich zu dir Chorus C G Du bist alles du bist alles fur mich Am F Du bist alles ich such dein Angesicht C G Du bist alles d
u bist alles fiir mich Am F Du bist alles ich liebe dich Vers 2 C G Am Halte dich nicht fest an dem was doch zer - bricht F Was wirklich wichtig ist sehn wir nur in seinem Licht C G Am Keinen Umweg mehr ich will nicht mehr im Kreis rou -tiern F Denn es gibt nur einen Weg Am G F Ich will mich ganz in dir verliern Tonart - C CCLI-Liednummer 5472893 © 2005 Reger, Simon Nutzung ausschlieglich im Rahmen der SongSelect-Nutzungsbedingungen. Alle Rechte vorbehalten. www.ccli.de CCLI-Lizenznummer 1293482
 "]],
    "OutputFileUrl": "",
    "OutputFileUrl2": "",
    "OutputFileUrl3": "",
    "Reserved": [],
    "OCRWords": [],
    "TaskDescription": null
} 

输出还将包含指向包含文本的文本文件(或 PDF 或 DOC(的链接,这可能对您更有用。

最新更新