Created
March 29, 2016 21:43
-
-
Save ashumkin/a291dbd17b9ade663afc08b2413e47b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Console: SaveAllText | |
// Description: SaveAllText input file | |
// Parameters: [input file] [output file] | |
/** Print help for savealltext */ | |
function savealltext_help() { | |
print(tr("Usage:")); | |
print("savealltext ["+tr("input file")+"] ["+tr("output file")+"]"); | |
print(" "+tr("Input file must exist")); | |
print(" "+tr("Output file must not exist")); | |
exit(1); | |
} | |
function savealltext_fail(err) { | |
print(tr("savealltext failed!")); | |
print(err); | |
exit(2); | |
} | |
function saveAsText_save(p,f) { | |
document=loadPdf(p) | |
qs=""; | |
pages=document.getPageCount(); | |
for (i=1;i<=pages;i++) { | |
pg=document.getPage(i); | |
text=pg.getText(); | |
qs+=text; | |
qs+="\n"; | |
} | |
saveFile(f,qs); | |
} | |
p=parameters(); | |
if (p.length!=2) { | |
savealltext_help("savealltext "+tr("is expecting two parameters")); | |
} | |
inFile=p[0]; | |
outFile=p[1]; | |
if (!exists(inFile)) savealltext_fail(tr("Input file '%1' does not exist").arg(inFile)); | |
if (exists(outFile)) savealltext_fail(tr("Output file '%1' already exist").arg(outFile)); | |
if (inFile==outFile) savealltext_fail(tr("Input and output files must be different")); | |
if (saveAsText_save(inFile,outFile)) { | |
} else { | |
print(tr("savealltext")+" :"+inFile+" -> "+outFile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment