-
-
Save gvangool/129962 to your computer and use it in GitHub Desktop.
Validate that an uploaded file is a PDF
This file contains hidden or 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
# Django: validate that an uploaded file is a valid PDF | |
import pyPdf # from http://pybrary.net/pyPdf/ | |
from pyPdf.utils import PdfReadError | |
class DocumentForm(forms.ModelForm): | |
pdf = forms.FileField() | |
class Meta: | |
model = Document | |
def clean_pdf(self): | |
file = self.cleaned_data['pdf'] | |
try: | |
pdf = pyPdf.PdfFileReader(file) | |
except PdfReadError: | |
raise forms.ValidationError, 'You must upload a valid PDF file' | |
print pdf.documentInfo | |
return file |
There is a way to know if pdf it's a pdf/A?
I need the same!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a way to know if pdf it's a pdf/A?