Update preview package

This commit is contained in:
Xuan Sang LE 2020-05-21 14:51:47 +02:00
parent 5df3106328
commit dd58a998d8
5 changed files with 77 additions and 78 deletions

View File

@ -78,11 +78,10 @@
}
renderPDF(file) {
var q, status;
return this.load(new Promise((resolve, reject) => {
var status;
status = `${file.info.name} (${file.info.size} Kb)`;
q = this._api.mid();
return file.read("binary").then((d) => {
this._api.loading(q, "RENDERING");
($(this.view)).removeClass();
return PDFJS.getDocument({
data: d
@ -91,7 +90,7 @@
fn = (p) => {
if (p > pdf.numPages) {
this.setStatus(`${status} - loaded`);
return this._api.loaded(q, "OK");
return resolve();
}
return pdf.getPage(p).then((page) => {
var canvas, context, div, renderContext, scale, viewport;
@ -111,16 +110,19 @@
page.render(renderContext);
this.setStatus(`${status} - ${p}/${pdf.numPages} loaded`);
return fn(p + 1);
}).catch(function(e) {
return reject(e);
});
};
return fn(1);
}).catch((err) => {
this.error(__("Cannot render the PDF file"));
return this._api.loaded(q, "FAIL");
}).catch(function(e) {
return reject(e);
});
}).catch((e) => {
this._api.loaded(q, "FAIL");
return this.error(__("Unable to read file: {}", file.path), e);
}).catch(function(e) {
return reject(e);
});
})).catch((e) => {
return this.error(__("Unable to view file: {}", file.path), e);
});
}

Binary file not shown.

View File

@ -58,17 +58,16 @@ class Preview extends this.OS.GUI.BaseApplication
($ @status).html t
renderPDF: (file) ->
@load new Promise (resolve, reject) =>
status = "#{file.info.name} (#{file.info.size} Kb)"
q = @_api.mid()
file.read("binary").then (d) =>
@_api.loading q, "RENDERING"
($ @view).removeClass()
PDFJS.getDocument { data: d }
.then (pdf) =>
fn = (p) =>
if p > pdf.numPages
@setStatus "#{status} - loaded"
return @_api.loaded q, "OK"
return resolve()
pdf.getPage(p).then (page) =>
scale = 1.5
viewport = page.getViewport scale
@ -85,13 +84,11 @@ class Preview extends this.OS.GUI.BaseApplication
page.render renderContext
@setStatus "#{status} - #{p}/#{pdf.numPages} loaded"
fn(p+1)
.catch (e) -> reject e
fn(1)
.catch (err) =>
@error __("Cannot render the PDF file")
@_api.loaded q, "FAIL"
.catch (e) =>
@_api.loaded q, "FAIL"
@error __("Unable to read file: {}", file.path), e
.catch (e) -> reject e
.catch (e) -> reject e
.catch (e) => @error __("Unable to view file: {}", file.path), e
renderSVG: (file) ->
($ @view).attr("class", "image")

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.0.1-a",
"version":"0.0.2-a",
"category":"Utils",
"iconclass":"fa fa-eye",
"mimes":["[^\/]*/.*pdf", "image/.*"]

View File

@ -32,7 +32,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/README.md",
"category": "Utils",
"author": "Xuan Sang LE",
"version": "0.0.1-a",
"version": "0.0.2-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/build/release/Preview.zip"
},
{