From 20599dce380b63af37433614d74778fb4f3e20b6 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Thu, 7 Mar 2019 01:45:20 -0500 Subject: cleaned up PDF render and fixed dragging to show annotations. --- src/client/views/nodes/PDFNode.tsx | 144 ++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 75 deletions(-) (limited to 'src/client/views') diff --git a/src/client/views/nodes/PDFNode.tsx b/src/client/views/nodes/PDFNode.tsx index 0390d5e0d..b6829f086 100644 --- a/src/client/views/nodes/PDFNode.tsx +++ b/src/client/views/nodes/PDFNode.tsx @@ -412,6 +412,29 @@ export class PDFNode extends React.Component { }); }, 1000); } + + onLoaded = (page: any) => { + if (this._mainDiv.current) { + this._mainDiv.current.childNodes.forEach((element) => { + if (element.nodeName == "DIV") { + element.childNodes[0].childNodes.forEach((e) => { + + if (e instanceof HTMLCanvasElement) { + this._pdfCanvas = e; + this._pdfContext = e.getContext("2d") + + } + + }) + } + }) + } + this.numPage = page.transport.numPages + if (this.perPage.length == 0) { //Makes sure it only runs once + this.perPage = [...Array(this.numPage)] + } + } + @action setScaling = (r: any) => { // bcz: the nativeHeight should really be set when the document is imported. @@ -425,90 +448,61 @@ export class PDFNode extends React.Component { this.saveThumbnail(); } } - render() { - let field = this.props.doc.Get(KeyStore.Thumbnail); - if (!this._interactive && field) { - let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" : - field instanceof ImageField ? field.Data.href : "http://cs.brown.edu/people/bcz/prairie.jpg"; - return ( -
- -
); + makeUIButtons() { + return ( +
+ + + + + + + + + +
); + } + makePdfRenderer() { + let proxy = this.makeImageProxyRenderer(); + let pdfUrl = this.props.doc.GetT(this.props.fieldKey, PDFField); + if ((!this._interactive && proxy) || !pdfUrl || pdfUrl == FieldWaiting) { + return proxy; } const renderHeight = 2400; let xf = this.props.doc.GetNumber(KeyStore.NativeHeight, 0) / renderHeight; - var pdfUrl = this.props.doc.GetT(this.props.fieldKey, PDFField); - if (!pdfUrl || pdfUrl == FieldWaiting) { - return (null); + return [ + this.pageInfo.area.filter(() => this.pageInfo.area).map((element: any) => element), + this.currAnno.map((element: any) => element), + this.makeUIButtons(), +
+ + + {({ measureRef }) => +
+ +
+ } +
+
+
+ ]; + } + makeImageProxyRenderer() { + let field = this.props.doc.Get(KeyStore.Thumbnail); + if (field) { + let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" : + field instanceof ImageField ? field.Data.href : "http://cs.brown.edu/people/bcz/prairie.jpg"; + return ; } + return (null); + } + render() { return (
- - {this.pageInfo.area.filter(() => { - return this.pageInfo.area - }).map((element: any) => { - return element - }) - } - {this.currAnno.map((element: any) => { - return element - })} - -
- - - - - - - - - -
- -
- - - {({ measureRef }) => -
- { - if (this._mainDiv.current) { - this._mainDiv.current.childNodes.forEach((element) => { - if (element.nodeName == "DIV") { - element.childNodes[0].childNodes.forEach((e) => { - - if (e instanceof HTMLCanvasElement) { - this._pdfCanvas = e; - this._pdfContext = e.getContext("2d") - - } - - }) - } - }) - } - this.numPage = page.transport.numPages - if (this.perPage.length == 0) { //Makes sure it only runs once - this.perPage = [...Array(this.numPage)] - } - } - } - /> -
- } -
-
-
+ {this.makePdfRenderer()}
); } -- cgit v1.2.3-70-g09d2