mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* pdfjs-dist module definition * Declare pdfjs export in react-pdf * Remove react-pdf/package.json, fix-up default export * Add pdfjs test to react-pdf
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import * as React from 'react';
|
|
import { Document, Page, pdfjs } from 'react-pdf';
|
|
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
|
|
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
|
|
|
|
interface State {
|
|
numPages: number | null;
|
|
pageNumber: number;
|
|
}
|
|
|
|
export class MyApp extends React.Component<{}, State> {
|
|
constructor(props: {}) {
|
|
super(props);
|
|
this.state = {
|
|
numPages: null,
|
|
pageNumber: 1,
|
|
};
|
|
}
|
|
|
|
onDocumentLoadSuccess = ({ numPages }: PDFDocumentProxy) => {
|
|
this.setState({ numPages });
|
|
}
|
|
|
|
render() {
|
|
const { pageNumber, numPages } = this.state;
|
|
|
|
return (
|
|
<div>
|
|
<Document
|
|
file="somefile.pdf"
|
|
onLoadSuccess={this.onDocumentLoadSuccess}
|
|
>
|
|
<Page pageNumber={pageNumber} />
|
|
</Document>
|
|
<p>Page {pageNumber} of {numPages}</p>
|
|
</div>
|
|
);
|
|
}
|
|
}
|