This commit is contained in:
yumoqing 2024-12-06 18:41:25 +08:00
parent 3c0aa87530
commit b7edc34bdd
2 changed files with 1 additions and 69 deletions

View File

@ -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 docxviewer.js \ binstreaming.js streaming_audio.js vadtext.js rtc.js docxviewer.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 pdfviewer.js" line.js pie.js bar.js gobang.js period.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

View File

@ -1,68 +0,0 @@
/*
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), 1);
}
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);