Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return { pdf: null };
});
const { options, onLoadProgress, onPassword } = this.props;
try {
// If another loading is in progress, let's cancel it
cancelRunningTask(this.runningTask);
const loadingTask = pdfjs.getDocument({ ...source, ...options });
loadingTask.onPassword = onPassword;
if (onLoadProgress) {
loadingTask.onProgress = onLoadProgress;
}
const cancellable = makeCancellable(loadingTask.promise);
this.runningTask = cancellable;
const pdf = await cancellable.promise;
this.setState((prevState) => {
if (prevState.pdf && prevState.pdf.fingerprint === pdf.fingerprint) {
return null;
}
return { pdf };
}, this.onLoadSuccess);
} catch (error) {
this.onLoadError(error);
}
}
loadAnnotations = async () => {
const { page } = this.props;
try {
const cancellable = makeCancellable(page.getAnnotations());
this.runningTask = cancellable;
const annotations = await cancellable.promise;
this.setState({ annotations }, this.onLoadSuccess);
} catch (error) {
this.onLoadError(error);
}
}
loadOutline = async () => {
const { pdf } = this.props;
this.setState((prevState) => {
if (!prevState.outline) {
return null;
}
return { outline: null };
});
try {
const cancellable = makeCancellable(pdf.getOutline());
this.runningTask = cancellable;
const outline = await cancellable.promise;
this.setState({ outline }, this.onLoadSuccess);
} catch (error) {
this.onLoadError(error);
}
}
loadTextItems = async () => {
const { page } = this.props;
try {
const cancellable = makeCancellable(page.getTextContent());
this.runningTask = cancellable;
const { items: textItems } = await cancellable.promise;
this.setState({ textItems }, this.onLoadSuccess);
} catch (error) {
this.onLoadError(error);
}
}
const pageNumber = this.getPageNumber();
if (!pageNumber) {
return;
}
this.setState((prevState) => {
if (!prevState.page) {
return null;
}
return { page: null };
});
try {
const cancellable = makeCancellable(pdf.getPage(pageNumber));
this.runningTask = cancellable;
const page = await cancellable.promise;
this.setState({ page }, this.onLoadSuccess);
} catch (error) {
this.setState({ page: false });
this.onLoadError(error);
}
}