-
-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move Vite 3 sample to vite3 directory * Add Vite 4 sample
- Loading branch information
Showing
16 changed files
with
2,175 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
body { | ||
margin: 0; | ||
background-color: #525659; | ||
font-family: Segoe UI, Tahoma, sans-serif; | ||
} | ||
|
||
.Example input, | ||
.Example button { | ||
font: inherit; | ||
} | ||
|
||
.Example header { | ||
background-color: #323639; | ||
box-shadow: 0 0 8px rgba(0, 0, 0, 0.5); | ||
padding: 20px; | ||
color: white; | ||
} | ||
|
||
.Example header h1 { | ||
font-size: inherit; | ||
margin: 0; | ||
} | ||
|
||
.Example__container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin: 10px 0; | ||
padding: 10px; | ||
} | ||
|
||
.Example__container__load { | ||
margin-top: 1em; | ||
color: white; | ||
} | ||
|
||
.Example__container__document { | ||
margin: 1em 0; | ||
} | ||
|
||
.Example__container__document .react-pdf__Document { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.Example__container__document .react-pdf__Page { | ||
max-width: calc(100% - 2em); | ||
box-shadow: 0 0 8px rgba(0, 0, 0, 0.5); | ||
margin: 1em; | ||
} | ||
|
||
.Example__container__document .react-pdf__Page canvas { | ||
max-width: 100%; | ||
height: auto !important; | ||
} | ||
|
||
.Example__container__document .react-pdf__message { | ||
padding: 20px; | ||
color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useState } from 'react'; | ||
import { Document, Page } from 'react-pdf/dist/esm/entry.vite'; | ||
import 'react-pdf/dist/esm/Page/AnnotationLayer.css'; | ||
import 'react-pdf/dist/esm/Page/TextLayer.css'; | ||
|
||
import './Sample.css'; | ||
|
||
const options = { | ||
cMapUrl: 'cmaps/', | ||
cMapPacked: true, | ||
standardFontDataUrl: 'standard_fonts/', | ||
}; | ||
|
||
export default function Sample() { | ||
const [file, setFile] = useState('./sample.pdf'); | ||
const [numPages, setNumPages] = useState(null); | ||
|
||
function onFileChange(event) { | ||
setFile(event.target.files[0]); | ||
} | ||
|
||
function onDocumentLoadSuccess({ numPages: nextNumPages }) { | ||
setNumPages(nextNumPages); | ||
} | ||
|
||
return ( | ||
<div className="Example"> | ||
<header> | ||
<h1>react-pdf sample page</h1> | ||
</header> | ||
<div className="Example__container"> | ||
<div className="Example__container__load"> | ||
<label htmlFor="file">Load from file:</label>{' '} | ||
<input onChange={onFileChange} type="file" /> | ||
</div> | ||
<div className="Example__container__document"> | ||
<Document file={file} onLoadSuccess={onDocumentLoadSuccess} options={options}> | ||
{Array.from(new Array(numPages), (el, index) => ( | ||
<Page key={`page_${index + 1}`} pageNumber={index + 1} /> | ||
))} | ||
</Document> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>react-pdf sample page</title> | ||
</head> | ||
<body> | ||
<div id="react-root"></div> | ||
<script type="module" src="./index.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import Sample from './Sample'; | ||
|
||
createRoot(document.getElementById('react-root')).render(<Sample />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "react-pdf-sample-page-vite4", | ||
"version": "4.0.0", | ||
"description": "A sample page for React-PDF.", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "vite build", | ||
"dev": "vite serve" | ||
}, | ||
"author": { | ||
"name": "Wojciech Maj", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-pdf": "latest" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-react": "^3.0.0", | ||
"vite": "^4.0.0" | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.