فهرست منبع

Watermark mit doc-Umwandlung

Global Cube 2 سال پیش
والد
کامیت
55746ff28e
6فایلهای تغییر یافته به همراه36 افزوده شده و 2 حذف شده
  1. 1 0
      .gitignore
  2. 7 0
      sandbox/db2_connect.py
  3. BIN
      tools/pdf/data/RE6404Siebrecht.doc
  4. BIN
      tools/pdf/data/RE6404Siebrecht.pdf
  5. 22 0
      tools/pdf/doc2pdf.py
  6. 6 2
      tools/pdf/pdf_watermark.py

+ 1 - 0
.gitignore

@@ -7,3 +7,4 @@ gcstruct/Kunden/**/info
 unzipped/
 GCStruct_Reisacher_Planung/config/logs/gcstruct.0.log
 o365_token.txt
+tools/pdf/data/mit_Briefpapier

+ 7 - 0
sandbox/db2_connect.py

@@ -0,0 +1,7 @@
+import ibm_db
+import ibm_db_dbi
+
+
+ibm_db_conn = ibm_db.connect('rbs05_db2', 'db2inst1', 'Gcbs12ma')
+conn = ibm_db_dbi.Connection(ibm_db_conn)
+conn.tables('SYSCAT', '%')

BIN
tools/pdf/data/RE6404Siebrecht.doc


BIN
tools/pdf/data/RE6404Siebrecht.pdf


+ 22 - 0
tools/pdf/doc2pdf.py

@@ -0,0 +1,22 @@
+import os
+from pathlib import Path
+from win32com.client import Dispatch
+
+
+wdFormatPDF = 17
+
+
+def doc2pdf(doc_file):
+    in_file = str(Path(doc_file).absolute())
+    out_file = in_file[:-4] + '.pdf'
+
+    word = Dispatch('Word.Application')
+    doc = word.Documents.Open(in_file)
+    doc.SaveAs(out_file, FileFormat=wdFormatPDF)
+    doc.Close()
+    word.Quit()
+
+
+if __name__ == '__main__':
+    doc2pdf(os.path.dirname(__file__) + '/data/RE6404Siebrecht.doc')
+    # add_watermark_to_folder(os.path.dirname(__file__) + '/data/')

+ 6 - 2
tools/pdf/pdf_watermark.py

@@ -1,6 +1,7 @@
 import PyPDF2
 import plac
 from pathlib import Path
+from doc2pdf import doc2pdf
 
 
 def add_watermark(input_file):
@@ -38,11 +39,14 @@ def add_watermark(input_file):
 
 
 def add_watermark_to_folder(base_dir):
+    for filename in Path(base_dir).glob('*.doc'):
+        doc2pdf(str(filename))
+
     for filename in Path(base_dir).glob('*.pdf'):
         add_watermark(str(filename))
         print(filename.name)
 
 
 if __name__ == '__main__':
-    plac.call(add_watermark_to_folder)
-    # add_watermark_to_folder(os.path.dirname(__file__) + '/data/')
+    # plac.call(add_watermark_to_folder)
+    add_watermark_to_folder(str(Path(__file__).parent) + '/data/')