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

Ft vil 384/fix pdf #920

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions server/__tests__/fileUpload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ beforeAll(() => {
});
beforeEach(() => {});
afterAll(() => {
const pathToFiles = 'server/fileUpload/images/1/';
fs.readdir(pathToFiles, (err, files) => {
if (err) {
console.error(err);
}
if (files) {
for (const file of files) {
fs.unlink(path.join(pathToFiles, file), (err) => {
if (err) {
console.error(err);
}
});
}
}
fs.rmdir(pathToFiles, (err) => {
if (err) {
console.error(err);
}
});
});

return appDataSource.destroy();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import React from 'react';
import React, { useState } from 'react';
import { Document, Page, pdfjs } from 'react-pdf';

pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
import 'react-pdf/dist/esm/Page/TextLayer.css';
import 'react-pdf/dist/esm/Page/AnnotationLayer.css';

pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;

const options = {
cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
};

export default function PdfDisplay({ url }: { url: string }) {
const [numPages, setNumPages] = useState<number>(1);
function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
setNumPages(numPages);
}

return (
<Document file={url}>
<Page width={380} renderTextLayer={true} renderAnnotationLayer={true} renderMode={'svg'} pageNumber={1} />
<Document options={options} file={url} onLoadSuccess={onDocumentLoadSuccess}>
{Array.from(Array(numPages).keys()).map((v) => (
<div
key={v}
style={{
marginTop: 10,
marginBottom: 10,
}}
>
<Page width={380} pageNumber={v + 1} />
</div>
))}
</Document>
);
}
4 changes: 4 additions & 0 deletions src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,7 @@ main {
left: 10vw;
}
}

.linkAnnotation {
opacity: 0;
}
Loading