bugfix
This commit is contained in:
parent
8da00bcdc4
commit
680fcfd434
@ -8,7 +8,7 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
|
|||||||
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
|
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
|
||||||
binstreaming.js streaming_audio.js vadtext.js rtc.js \
|
binstreaming.js streaming_audio.js vadtext.js rtc.js \
|
||||||
llm_dialog.js llm.js websocket.js datarow.js tabular.js \
|
llm_dialog.js llm.js websocket.js datarow.js tabular.js \
|
||||||
line.js pie.js bar.js gobang.js period.js "
|
line.js pie.js bar.js gobang.js period.js pdfviewer.js "
|
||||||
echo ${SOURCES}
|
echo ${SOURCES}
|
||||||
cat ${SOURCES} > ../dist/bricks.js
|
cat ${SOURCES} > ../dist/bricks.js
|
||||||
# uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js
|
# uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js
|
||||||
|
@ -418,6 +418,7 @@ hr {
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
padding: 3px;
|
||||||
background-color:#fefedd;
|
background-color:#fefedd;
|
||||||
border-top-left-radius: 10px;
|
border-top-left-radius: 10px;
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
|
68
bricks/pdfviewer.js
Normal file
68
bricks/pdfviewer.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
https://mozilla.github.io/pdf.js download pdf from here
|
||||||
|
or add follow line to html file body tag
|
||||||
|
<script src="//mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>
|
||||||
|
*/
|
||||||
|
|
||||||
|
var bricks = window.bricks || {}
|
||||||
|
|
||||||
|
bricks.PDFviewer = class extends bricks.VBox {
|
||||||
|
/*
|
||||||
|
url:
|
||||||
|
*/
|
||||||
|
constructor(opts){
|
||||||
|
super(opts);
|
||||||
|
this.curpage = null;
|
||||||
|
this.pdf = null;
|
||||||
|
bricks.app.bind('keydown', this.key_action.bind(this));
|
||||||
|
schedule_once(this.renderPage(1), 0.2);
|
||||||
|
}
|
||||||
|
key_action(e){
|
||||||
|
if (!this.curpage) return;
|
||||||
|
switch(e.key){
|
||||||
|
case 'Enter':
|
||||||
|
case ' ':
|
||||||
|
case 'ArrowDown':
|
||||||
|
this.renderPage(this.curpage+1);
|
||||||
|
break;
|
||||||
|
case 'ArrowUp':
|
||||||
|
this.renderPage(this.curpage-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async renderPage(pn){
|
||||||
|
if (pn < 1) return;
|
||||||
|
this.curpage = pn;
|
||||||
|
if (!this.pdf) {
|
||||||
|
pdfjsLib.getDocument(this.url).promise.then(function(pdf){
|
||||||
|
this.pdf = pdf;
|
||||||
|
pdf.getPage(pn).promise.then(function(page){
|
||||||
|
this._render_page(page);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.pdf.getPage(pn).promise.then(function(page){
|
||||||
|
this._render_page(page);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_render_page(page){
|
||||||
|
var scale = 1.5;
|
||||||
|
var viewport = page.getViewport({scale: scale});
|
||||||
|
var canvasElement = document.createElement('canvas');
|
||||||
|
var context = canvasElement.getContext('2d');
|
||||||
|
|
||||||
|
canvasElement.height = viewport.height;
|
||||||
|
canvasElement.width = viewport.width;
|
||||||
|
|
||||||
|
var renderContext = {
|
||||||
|
canvasContext: context,
|
||||||
|
viewport: viewport
|
||||||
|
};
|
||||||
|
page.render(renderContext);
|
||||||
|
this.dom_element.innerHTML = '';
|
||||||
|
this.dom_element.appendChild(canvasElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bricks.Factory.register('PDFviewer', bricks.PDFviewer);
|
Loading…
Reference in New Issue
Block a user