Skip to content

Commit

Permalink
Add loading/error message, add a page limit on the imported pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Wistaro committed Feb 18, 2018
1 parent 43ebdeb commit e97fe1b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Binary file added images/ajax-loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -51,7 +51,8 @@ <h3 id="topTitle" style="display:none">zText: convertisseur pdf/texte => 8xp</h3
Tu souhaites organiser ton cours en plusieurs parties avec un menu ? <button id="toggleAdvanced" class="btn btn-success btn-xs">Clique-ici</button><br /><br />
Tu peux aussi charger le texte d'un fichier PDF :
<input type="file" id="pdfFile" onchange="handlePdf(this.files)"/>
<br><br>
<span class="loaderPdf" id="loaderPdf"></span>
<br /><br />
</div>
<div id="textareaWrapper">
<textarea id="myText0" title="Ton texte ici" name="myText0" placeholder="Écris ton texte dans cette zone" required></textarea>
Expand Down
30 changes: 20 additions & 10 deletions pdf2text/functions.js
Expand Up @@ -24,10 +24,12 @@ function getPageText(pageNum, PDFDocumentInstance) {

function handlePdf(data){

document.getElementById('loaderPdf').innerHTML = "<b><font color=#FE2E2E>Chargement du fichier en cours...</font></b>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;<img src='images/ajax-loader.gif' alt='loader' height='10px' width='10px'/>";
document.getElementById('myText0').innerHTML = "* Début du fichier PDF*\n";

var fileList = this.files;
var MyFile = data[0];
var maxPages = 10;
var fileReader = new FileReader();

fileReader.onload = function() {
Expand All @@ -39,22 +41,30 @@ function handlePdf(data){
var pdfDocument = pdf;
var pagesPromises = [];

for (var i = 0; i < pdf.pdfInfo.numPages; i++) {
(function (pageNumber) {
pagesPromises.push(getPageText(pageNumber, pdfDocument));
})(i + 1);
}
if(pdf.pdfInfo.numPages <= maxPages){

Promise.all(pagesPromises).then(function (pagesText) {
document.getElementById('myText0').innerHTML += pagesText; //fill textarea with extracted text
for (var i = 0; i < pdf.pdfInfo.numPages; i++) {
(function (pageNumber) {
pagesPromises.push(getPageText(pageNumber, pdfDocument));
})(i + 1);
}

Promise.all(pagesPromises).then(function (pagesText) {
document.getElementById('myText0').innerHTML += pagesText; //fill textarea with extracted text

});

delete data;
});
document.getElementById('loaderPdf').innerHTML = "<b><font color=#3ADF00>Fichier pdf chargé!</font></b>";
}else{
alert("Le document comporte trop de pages! Maxmimum "+maxPages+" pages.");
document.getElementById('loaderPdf').innerHTML = "<b><font color=#FE2E2E>Echec lors du chargement fichier pdf: trop de pages.</font></b>";


}

}, function (reason) {
alert(reason);
document.getElementById('loaderPdf').innerHTML = "<b><font color=#FE2E2E>"+reason+"</font></b>";

});

};
Expand Down
3 changes: 3 additions & 0 deletions style.css
Expand Up @@ -145,4 +145,7 @@ textarea.withLargeViewer[data-calc='82A'] {

#advancedCreator {
display: none;
}
.loaderPdf{
font-size: 11px;
}

0 comments on commit e97fe1b

Please sign in to comment.