diff --git a/bricks/build.sh b/bricks/build.sh index 78f050a..cd56490 100755 --- a/bricks/build.sh +++ b/bricks/build.sh @@ -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 \ binstreaming.js streaming_audio.js vadtext.js rtc.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} cat ${SOURCES} > ../dist/bricks.js # uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js diff --git a/bricks/css/bricks.css b/bricks/css/bricks.css index 2e29901..d71f1d8 100755 --- a/bricks/css/bricks.css +++ b/bricks/css/bricks.css @@ -418,6 +418,7 @@ hr { margin-left: 5px; margin-right: auto; margin-bottom: 10px; + padding: 3px; background-color:#fefedd; border-top-left-radius: 10px; border-top-right-radius: 0; diff --git a/bricks/pdfviewer.js b/bricks/pdfviewer.js new file mode 100644 index 0000000..b7b80d0 --- /dev/null +++ b/bricks/pdfviewer.js @@ -0,0 +1,68 @@ +/* +https://mozilla.github.io/pdf.js download pdf from here +or add follow line to html file body tag + +*/ + +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);