OpenSlides/server/openslides/mediafiles/utils.py
FinnStutzenstein 2bcab5d098
Repository restructure
- moved all server related things into the folder `server`, so this
configuration is parallel to the client.
- All main "services" are now folders in the root directory
- Added Dockerfiles to each service (currently server and client)
- Added a docker compose configuration to start everything together.
Currently there are heavy dependencies into https://github.com/OpenSlides/openslides-docker-compose
- Resturctured the .gitignore. If someone needs something excluded,
please add it to the right section.
- Added initial build setup with Docker and docker-compose.
- removed setup.py. We won't deliver OpenSlides via pip anymore.
2020-08-21 08:11:13 +02:00

28 lines
728 B
Python

from PyPDF2 import PdfFileReader
from PyPDF2.utils import PdfReadError
def bytes_to_human(size):
# TODO: Read http://stackoverflow.com/a/1094933 and think about it.
if size < 1024:
size_string = "< 1 kB"
elif size >= 1024 * 1024:
mB = size / 1024 / 1024
size_string = "%d MB" % mB
else:
kB = size / 1024
size_string = "%d kB" % kB
return size_string
def get_pdf_information(mediafile):
result = {}
try:
pdf = PdfFileReader(mediafile)
result["pages"] = pdf.getNumPages()
except PdfReadError:
# File could be encrypted but not be detected by PyPDF.
result["pages"] = 0
result["encrypted"] = True
return result