mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-26 04:08:21 +01:00
Update preview package
This commit is contained in:
parent
5df3106328
commit
dd58a998d8
@ -78,49 +78,51 @@
|
||||
}
|
||||
|
||||
renderPDF(file) {
|
||||
var q, 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
|
||||
}).then((pdf) => {
|
||||
var fn;
|
||||
fn = (p) => {
|
||||
if (p > pdf.numPages) {
|
||||
this.setStatus(`${status} - loaded`);
|
||||
return this._api.loaded(q, "OK");
|
||||
}
|
||||
return pdf.getPage(p).then((page) => {
|
||||
var canvas, context, div, renderContext, scale, viewport;
|
||||
scale = 1.5;
|
||||
viewport = page.getViewport(scale);
|
||||
div = ($("<div/>")).attr("id", "page-" + (page.pageIndex + 1));
|
||||
($(this.view)).append(div);
|
||||
canvas = ($("<canvas>"))[0];
|
||||
div.append(canvas);
|
||||
context = canvas.getContext('2d');
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
renderContext = {
|
||||
canvasContext: context,
|
||||
viewport: viewport
|
||||
};
|
||||
page.render(renderContext);
|
||||
this.setStatus(`${status} - ${p}/${pdf.numPages} loaded`);
|
||||
return fn(p + 1);
|
||||
});
|
||||
};
|
||||
return fn(1);
|
||||
}).catch((err) => {
|
||||
this.error(__("Cannot render the PDF file"));
|
||||
return this._api.loaded(q, "FAIL");
|
||||
return this.load(new Promise((resolve, reject) => {
|
||||
var status;
|
||||
status = `${file.info.name} (${file.info.size} Kb)`;
|
||||
return file.read("binary").then((d) => {
|
||||
($(this.view)).removeClass();
|
||||
return PDFJS.getDocument({
|
||||
data: d
|
||||
}).then((pdf) => {
|
||||
var fn;
|
||||
fn = (p) => {
|
||||
if (p > pdf.numPages) {
|
||||
this.setStatus(`${status} - loaded`);
|
||||
return resolve();
|
||||
}
|
||||
return pdf.getPage(p).then((page) => {
|
||||
var canvas, context, div, renderContext, scale, viewport;
|
||||
scale = 1.5;
|
||||
viewport = page.getViewport(scale);
|
||||
div = ($("<div/>")).attr("id", "page-" + (page.pageIndex + 1));
|
||||
($(this.view)).append(div);
|
||||
canvas = ($("<canvas>"))[0];
|
||||
div.append(canvas);
|
||||
context = canvas.getContext('2d');
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
renderContext = {
|
||||
canvasContext: context,
|
||||
viewport: viewport
|
||||
};
|
||||
page.render(renderContext);
|
||||
this.setStatus(`${status} - ${p}/${pdf.numPages} loaded`);
|
||||
return fn(p + 1);
|
||||
}).catch(function(e) {
|
||||
return reject(e);
|
||||
});
|
||||
};
|
||||
return fn(1);
|
||||
}).catch(function(e) {
|
||||
return reject(e);
|
||||
});
|
||||
}).catch(function(e) {
|
||||
return reject(e);
|
||||
});
|
||||
}).catch((e) => {
|
||||
this._api.loaded(q, "FAIL");
|
||||
return this.error(__("Unable to read file: {}", file.path), e);
|
||||
})).catch((e) => {
|
||||
return this.error(__("Unable to view file: {}", file.path), e);
|
||||
});
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -58,40 +58,37 @@ class Preview extends this.OS.GUI.BaseApplication
|
||||
($ @status).html t
|
||||
|
||||
renderPDF: (file) ->
|
||||
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"
|
||||
pdf.getPage(p).then (page) =>
|
||||
scale = 1.5
|
||||
viewport = page.getViewport scale
|
||||
div = ($ "<div/>").attr("id", "page-" + (page.pageIndex + 1))
|
||||
($ @view).append div
|
||||
canvas = ($ "<canvas>")[0]
|
||||
div.append canvas
|
||||
context = canvas.getContext '2d'
|
||||
canvas.height = viewport.height
|
||||
canvas.width = viewport.width
|
||||
renderContext =
|
||||
canvasContext: context
|
||||
viewport: viewport
|
||||
page.render renderContext
|
||||
@setStatus "#{status} - #{p}/#{pdf.numPages} loaded"
|
||||
fn(p+1)
|
||||
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
|
||||
@load new Promise (resolve, reject) =>
|
||||
status = "#{file.info.name} (#{file.info.size} Kb)"
|
||||
file.read("binary").then (d) =>
|
||||
($ @view).removeClass()
|
||||
PDFJS.getDocument { data: d }
|
||||
.then (pdf) =>
|
||||
fn = (p) =>
|
||||
if p > pdf.numPages
|
||||
@setStatus "#{status} - loaded"
|
||||
return resolve()
|
||||
pdf.getPage(p).then (page) =>
|
||||
scale = 1.5
|
||||
viewport = page.getViewport scale
|
||||
div = ($ "<div/>").attr("id", "page-" + (page.pageIndex + 1))
|
||||
($ @view).append div
|
||||
canvas = ($ "<canvas>")[0]
|
||||
div.append canvas
|
||||
context = canvas.getContext '2d'
|
||||
canvas.height = viewport.height
|
||||
canvas.width = viewport.width
|
||||
renderContext =
|
||||
canvasContext: context
|
||||
viewport: viewport
|
||||
page.render renderContext
|
||||
@setStatus "#{status} - #{p}/#{pdf.numPages} loaded"
|
||||
fn(p+1)
|
||||
.catch (e) -> reject e
|
||||
fn(1)
|
||||
.catch (e) -> reject e
|
||||
.catch (e) -> reject e
|
||||
.catch (e) => @error __("Unable to view file: {}", file.path), e
|
||||
|
||||
renderSVG: (file) ->
|
||||
($ @view).attr("class", "image")
|
||||
|
@ -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/.*"]
|
||||
|
@ -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"
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user