Browse Source

Add files via upload

Jannis Hajda 6 years ago
parent
commit
1a66f83a2f
3 changed files with 27 additions and 0 deletions
  1. 2 0
      Dockerfile
  2. 9 0
      docker-compose.yaml
  3. 16 0
      src/main.py

+ 2 - 0
Dockerfile

@@ -0,0 +1,2 @@
+FROM python:3.8.0a3-alpine
+RUN apk add libreoffice

+ 9 - 0
docker-compose.yaml

@@ -0,0 +1,9 @@
+version: '3'
+services:
+  doc2pdf:
+    container_name: doc2pdf
+    build: .
+    working_dir: /usr/src/app
+    command: python main.py
+    volumes:
+      - ./src:/usr/src/app

+ 16 - 0
src/main.py

@@ -0,0 +1,16 @@
+from subprocess import Popen, PIPE
+import glob
+
+files = []
+types = ['doc', 'docx', 'pptx', 'ppt']
+
+for type in types:
+    files.extend(glob.glob('./input/*.' + type))
+
+for file in files:
+    p = Popen(['soffice', '--headless', '--convert-to', 'pdf', file, '--outdir', './output'], stdout=PIPE, stderr=PIPE)
+    output, error = p.communicate()
+    if p.returncode != 0:
+        print("Couldn't convert to following file: %d %s %s" % (file, output, error))
+
+print("Finished converting! Exiting process.")