PdfPage.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. import Page from '../components/Page';
  3. import Annotation from './Annotation';
  4. import { getPdfPage } from '../helpers/pdf';
  5. import useStore from '../store';
  6. type Props = {
  7. index: number;
  8. renderingState: RenderingStateType;
  9. };
  10. const PdfPage: React.FC<Props> = ({ index, renderingState }: Props) => {
  11. const [
  12. {
  13. viewport,
  14. pdf,
  15. rotation,
  16. annotations,
  17. scale,
  18. watermark,
  19. currentPage,
  20. queryString,
  21. matchesMap,
  22. },
  23. ] = useStore();
  24. const getAnnotationWithPage = (
  25. arr: AnnotationType[],
  26. pageNum: number
  27. ): React.ReactNode[] => {
  28. const result: React.ReactNode[] = [];
  29. arr.forEach((ele: AnnotationType, i: number) => {
  30. const page = ele.obj_attr ? ele.obj_attr.page + 1 : -1;
  31. if (page === pageNum) {
  32. result.push(
  33. <Annotation key={ele.id} scale={scale} index={i} {...ele} />
  34. );
  35. }
  36. });
  37. return result;
  38. };
  39. return (
  40. <Page
  41. pageNum={index}
  42. renderingState={renderingState}
  43. viewport={viewport}
  44. scale={scale}
  45. getPage={(): Promise<any> => getPdfPage(pdf, index)}
  46. rotation={rotation}
  47. watermark={watermark}
  48. annotations={getAnnotationWithPage(annotations, index)}
  49. currentPage={currentPage}
  50. queryString={queryString}
  51. matchesMap={matchesMap}
  52. />
  53. );
  54. };
  55. export default PdfPage;