aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf/PDFViewer.tsx
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-06-17 13:42:21 -0400
committeryipstanley <stanley_yip@brown.edu>2019-06-17 13:42:21 -0400
commit122607408882617235af255af84ce78828b7982f (patch)
treed91a7f742a2ac23ba7de3d19e3051608c9ac66a3 /src/client/views/pdf/PDFViewer.tsx
parent90c14f3ad8d9e48698c516bc6549143912e19236 (diff)
page sizes loaded
Diffstat (limited to 'src/client/views/pdf/PDFViewer.tsx')
-rw-r--r--src/client/views/pdf/PDFViewer.tsx30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 9becfb419..d74a16f3f 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -23,6 +23,7 @@ import { Dictionary } from "typescript-collections";
import * as rp from "request-promise";
import { restProperty } from "babel-types";
import { DocServer } from "../../DocServer";
+import { number } from "prop-types";
export const scale = 2;
interface IPDFViewerProps {
@@ -141,10 +142,33 @@ class Viewer extends React.Component<IViewerProps> {
setTimeout(() => {
// this.renderPages(this.startIndex, this.endIndex, true);
- this.saveThumbnail();
+ this.initialLoad();
}, 1000);
}
+ @action
+ initialLoad = () => {
+ let pdf = this.props.pdf;
+ if (pdf) {
+ this._pageSizes = Array<{ width: number, height: number }>(pdf.numPages);
+ let rendered = 0;
+ for (let i = 0; i < pdf.numPages; i++) {
+ pdf.getPage(i + 1).then(
+ (page: Pdfjs.PDFPageProxy) => {
+ runInAction(() => {
+ this._pageSizes[i] = { width: page.view[2] * scale, height: page.view[3] * scale };
+ });
+ console.log(`page ${i} size retreieved`);
+ rendered++;
+ if (rendered === pdf!.numPages - 1) {
+ this.saveThumbnail();
+ }
+ }
+ );
+ }
+ }
+ }
+
private mainCont = (div: HTMLDivElement | null) => {
if (this._dropDisposer) {
this._dropDisposer();
@@ -186,7 +210,7 @@ class Viewer extends React.Component<IViewerProps> {
drop = async (e: Event, de: DragManager.DropEvent) => {
if (de.data instanceof DragManager.LinkDragData) {
let sourceDoc = de.data.linkSourceDocument;
- let destDoc = this.makeAnnotationDocument(sourceDoc);
+ let destDoc = this.makeAnnotationDocument(sourceDoc, 1, "red");
let targetAnnotations = DocListCast(this.props.parent.Document.annotations);
if (targetAnnotations) {
targetAnnotations.push(destDoc);
@@ -392,7 +416,7 @@ class Viewer extends React.Component<IViewerProps> {
let numPages = this.props.pdf ? this.props.pdf.numPages : 0;
let index = 0;
let currOffset = vOffset;
- while (index < numPages && currOffset - (this._pageSizes[index] ? this._pageSizes[index].height : 792 * scale) > 0) {
+ while (index < this._pageSizes.length && currOffset - (this._pageSizes[index] ? this._pageSizes[index].height : 792 * scale) > 0) {
currOffset -= this._pageSizes[index] ? this._pageSizes[index].height : this._pageSizes[0].height;
index++;
}