Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to render PDF using DocumentWrapper component #207

Open
minump opened this issue Nov 27, 2023 · 1 comment
Open

Unable to render PDF using DocumentWrapper component #207

minump opened this issue Nov 27, 2023 · 1 comment

Comments

@minump
Copy link

minump commented Nov 27, 2023

Installed AllenAI pdf-component-library using npm install @allenai/pdf-components . Used the code from Reader component. Unable to render Pdf documents. Errors : Unable to call method(). The context Provider may not be setup correctly.. Screenshot of console log below.

Relevant code snippets below :

package.json:

"dependencies": {
		"@allenai/pdf-components": "^1.0.1",

src/components/Pdf.js:

import React, { useEffect, useRef, useState } from "react";
import {
	DocumentContext,
	DocumentWrapper,
	Overlay,
	PageWrapper,
	RENDER_TYPE,
	ScrollContext,
} from '@allenai/pdf-components';

export default function Pdf(props) {
	const { pageDimensions, numPages } = React.useContext(DocumentContext);
	const { setScrollRoot } = React.useContext(ScrollContext);

	React.useEffect(() => {
		setScrollRoot(null);
	}, []);

	// ref for the div in which the Document component renders
	const pdfContentRef = React.createRef();

	// ref for the scrollable region where the pages are rendered
	const pdfScrollableRef = React.createRef();

	const samplePdfUrl = 'https://arxiv.org/pdf/2112.07873.pdf';

	return (
		<div>
			<div className="reader__container">
				<DocumentWrapper
					className="reader__main"
					file={samplePdfUrl}
					inputRef={pdfContentRef}
					renderType={RENDER_TYPE.SINGLE_CANVAS}>
					<div className="reader__page-list" ref={pdfScrollableRef}>
						{Array.from({ length: numPages }).map((_, i) => (
							<PageWrapper key={i} pageIndex={i} renderType={RENDER_TYPE.SINGLE_CANVAS}>
				
							</PageWrapper>
						))}
					</div>
				</DocumentWrapper>
			</div>
		</div>
	);
}

Screenshot 2023-11-27 at 10 46 05 AM

Any help is appreciated.

@itsrun
Copy link

itsrun commented Aug 3, 2024

Hi you should wrap this component around ContextProvider when using it (e.g., in App.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants