aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/views/nodes/PDFBox.tsx4
-rw-r--r--src/client/views/pdf/PDFViewer.tsx50
2 files changed, 31 insertions, 23 deletions
diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx
index 217d7b5e1..7e335e75e 100644
--- a/src/client/views/nodes/PDFBox.tsx
+++ b/src/client/views/nodes/PDFBox.tsx
@@ -14,7 +14,7 @@ import { FieldView, FieldViewProps } from './FieldView';
import { pageSchema } from "./ImageBox";
import "./PDFBox.scss";
import React = require("react");
-import { NumCast } from "../../../new_fields/Types";
+import { NumCast, StrCast } from "../../../new_fields/Types";
import { makeInterface } from "../../../new_fields/Schema";
import { PDFViewer } from "../pdf/PDFViewer";
@@ -77,7 +77,7 @@ export class PDFBox extends DocComponent<FieldViewProps, PdfDocument>(PdfDocumen
render() {
trace();
- const pdfUrl = window.origin + RouteStore.corsProxy + "/https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf";
+ const pdfUrl = window.origin + RouteStore.corsProxy + "/" + StrCast(this.props.Document.title);
let classname = "pdfBox-cont" + (this.props.isSelected() && !InkingControl.Instance.selectedTool && !this._alt ? "-interactive" : "");
return (
<div onScroll={this.onScroll} style={{ overflow: "scroll", height: `${NumCast(this.props.Document.nativeWidth ? this.props.Document.nativeWidth : 300)}px` }} onWheel={(e: React.WheelEvent) => e.stopPropagation()} className={classname}>
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 999cb6378..374e598a4 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -91,24 +91,24 @@ class Viewer extends React.Component<IViewerProps> {
}
saveThumbnail = () => {
- this.props.parent.props.Document.thumbnailY = FieldValue(this.scrollY, 0);
- this._renderAsSvg = false;
- setTimeout(() => {
- let nwidth = FieldValue(this.props.parent.Document.nativeWidth, 0);
- htmlToImage.toPng(this.props.mainCont.current!, { width: nwidth, height: nwidth, quality: 0.8, })
- .then(action((dataUrl: string) => {
- SearchBox.convertDataUri(dataUrl, `icon${this.props.parent.Document[Id]}_${this.startIndex}`).then((returnedFilename) => {
- if (returnedFilename) {
- let url = DocServer.prepend(returnedFilename);
- this.props.parent.props.Document.thumbnail = new ImageField(new URL(url));
- }
- runInAction(() => this._renderAsSvg = true);
- });
- }))
- .catch(function (error: any) {
- console.error("Oops, something went wrong!", error);
- });
- }, 1250);
+ // this.props.parent.props.Document.thumbnailY = FieldValue(this.scrollY, 0);
+ // this._renderAsSvg = false;
+ // setTimeout(() => {
+ // let nwidth = FieldValue(this.props.parent.Document.nativeWidth, 0);
+ // htmlToImage.toPng(this.props.mainCont.current!, { width: nwidth, height: nwidth, quality: 0.8, })
+ // .then(action((dataUrl: string) => {
+ // SearchBox.convertDataUri(dataUrl, `icon${this.props.parent.Document[Id]}_${this.startIndex}`).then((returnedFilename) => {
+ // if (returnedFilename) {
+ // let url = DocServer.prepend(returnedFilename);
+ // this.props.parent.props.Document.thumbnail = new ImageField(new URL(url));
+ // }
+ // runInAction(() => this._renderAsSvg = true);
+ // });
+ // }))
+ // .catch(function (error: any) {
+ // console.error("Oops, something went wrong!", error);
+ // });
+ // }, 1250);
}
@computed get scrollY(): number {
@@ -338,15 +338,23 @@ class Page extends React.Component<IPageProps> {
let scale = 1;
let viewport = page.getViewport(scale);
let canvas = this.canvas.current;
- if (canvas) {
- let context = canvas.getContext("2d");
+ let tempCanvas = document.createElement('canvas')
+ if (tempCanvas && canvas) {
+ let ctx = canvas.getContext("2d");
+ let context = tempCanvas.getContext("2d");
+ tempCanvas.width = viewport.width;
canvas.width = viewport.width;
this._width = viewport.width;
+ tempCanvas.height = viewport.height;
canvas.height = viewport.height;
this._height = viewport.height;
this.props.pageLoaded(this._currPage, viewport);
if (context) {
- page.render({ canvasContext: context, viewport: viewport });
+ page.render({ canvasContext: context, viewport: viewport }).promise.then(() => {
+ if (context && ctx) {
+ ctx.putImageData(context.getImageData(0, 0, tempCanvas.width, tempCanvas.height), 0, 0);
+ }
+ });
page.getTextContent().then((res: Pdfjs.TextContent) => {
//@ts-ignore
let textLayer = Pdfjs.renderTextLayer({