Skip to content

Commit

Permalink
flow control workinggit status! release time
Browse files Browse the repository at this point in the history
  • Loading branch information
axfelix committed Jul 15, 2020
1 parent b53f790 commit d824553
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ <h3>Folder containing PDFs</h3>
<br/><br/>

<div class="button" id="button">
<button class="btn btn-primary" id="ocr">OCR</button>
<button class="btn btn-primary" id="ocr" style="display:inline;">OCR</button>
</div>
<div class="waiting" id="waiting" style="display:none;">
<p>Reticulating splines...</p>
</div>

<br/><br/>
Expand Down
36 changes: 21 additions & 15 deletions ochre.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,36 @@ function setlocation() {
}

function ocr() {
buttonBlock = document.getElementById("ocr");
buttonBlock = document.getElementById("button");
buttonBlock.style.display = "none";
waitingBlock = document.getElementById("waiting");
waitingBlock.style.display = "inline";
fs.readdir(document.getElementById("pdfdir").value, function (err, files) {
if (err) {
return console.log("Couldn't parse directory path.");
}
files.forEach(function (file) {
let input = path.join(document.getElementById("pdfdir").value, file);
let tempdirObject = tmp.dirSync();
let tempdir = tempdirObject.name;
let outpath = path.join(tempdir, "out-%05d.png");
execSync(commandJoin([path.join("win","gs","bin","gswin64c.exe"), "-o", path.join(tempdir, "%05d.png"), "-sDEVICE=png16m",
"-r300", "-dPDFFitPage=true", input]));
glob(path.join(tempdir, "*.png"), function (er, files) {
files.forEach(f => execSync(commandJoin([path.join("win","Tesseract-OCR","tesseract.exe"), f, path.join(tempdir, path.parse(f).name), "pdf"])));
let input = path.join(document.getElementById("pdfdir").value, file);
let tempdirObject = tmp.dirSync();
let tempdir = tempdirObject.name;
execSync([path.join("win","gs","bin","gswin64c.exe"), "-o", path.join(tempdir, "%05d.png"), "-sDEVICE=png16m", "-r300", "-dPDFFitPage=true", input].map(x => `"${x}"`).join(' '))
var itemsProcessed = 0;
glob(path.join(tempdir, "*.png"), function (er, files) {
files.forEach(f => {
execSync(commandJoin([path.join("win","Tesseract-OCR","tesseract.exe"), f, path.join(tempdir, path.parse(f).name), "pdf"]));
itemsProcessed++;
if(itemsProcessed === files.length) {
let joined_file = path.join(tempdir, "joined.pdf");
execSync(commandJoin([path.join("win","PDFtk","bin","pdftk.exe"), path.join(tempdir, "*.pdf"), "cat", "output", joined_file]));
let output = input.concat('.ocr.pdf')
execSync(commandJoin([path.join("win","gs","bin","gswin64c.exe"), "-sDEVICE=pdfwrite", "-sPAPERSIZE=letter", "-dFIXEDMEDIA", "-dPDFFitPage", "-o", output, joined_file]));
buttonBlock.style.display = "block";
waitingBlock.style.display = "none";
}
});
let pdfs = glob.sync(path.join(tempdir, "*.pdf")).sort();
let joined_file = path.join(tempdir, "joined.pdf");
execSync(commandJoin([path.join("win","PDFtk","bin","pdftk.exe"), pdfs, "cat", "output", joined_file]));
let output = input.concat('.ocr.pdf')
execSync(commandJoin([path.join("win","gs","bin","gswin64.exe"), "-sDEVICE=pdfwrite", "-sPAPERSIZE=letter", "-dFIXEDMEDIA", "-dPDFFitPage", "-o", output, joined_file]));
});
});
});
buttonBlock.style.display = "block";
}

document.getElementById("ocr").addEventListener("click", ocr);
Expand Down

0 comments on commit d824553

Please sign in to comment.