A lightweight TypeScript library for inspecting PDF file signatures in the browser and detecting files that were renamed with a .pdf extension.
Client-side file validation improves user feedback but does not replace server-side validation, malware scanning, or security controls.
- ⚛️ React 18
- ⛑ TypeScript
- ⛑ Vite
- 📏 ESLint
- 💖 Prettier
NPM:
npm i pdf-front-validatorYarn
yarn add pdf-front-validatorReact example
import { validateFilePDF } from 'pdf-front-validator'
function App() {
const selectedFile = e.target.files[0]
validateFilePDF(selectedFile)
.then((result) => {
if (result !== undefined) {
// It's a PDF file
} else {
// It's not a PDF file
}
})
.catch((error) => {
console.error("Error to validate PDF File. ln: 58 Error => ", error);
return;
});
}Made with 💗 by Patrick Gratão