0

I have used a .bat that references a .py script which converts Word, Excel and PowerPoint outputs into temporary .pdf versions that are then compressed into a single .pdf output file. Recently the .bat has not been successful at converting the word doc into a pdf.

I am thinking that 1) an updated version of the PyPDF2 package is needed or 2) there is a relationship to the 'wordFormatpdf = 17', see # In[12]: below -

coding: utf-8

# In[1]:

import sys
import os
import shutil
import pip
import comtypes.client


#!pip install PyPDF2
from PyPDF2 import PdfFileMerger


# In[2]:

#create tempfolder for pdfs
#iterate over files in project folder
#open files based on file extension
#convert files that are not pdf to pdf
#append files to final pdf
#save pdf to archive folder
#delete temp folder


# In[11]:

folder = raw_input('1) Enter path to project location: ')
archive = raw_input('2) Enter path to store final pdf packet: ')


# In[12]:

#convert word to pdf
def doc2pdf(infile,outfile):
    wdFormatPDF = 17
    word = comtypes.client.CreateObject('Word.Application')
    word.Visible = False
    doc = word.Documents.open(infile)
    doc.SaveAs(outfile, FileFormat=wdFormatPDF)
    doc.Close()
    word.Quit()
    pdf = file(outfile,'rb')
    if pdf:pdf.close()
    return 'Cover Letter and Response Converted to PDF'

fact that there is an updated Office package that was installed this past month (May 11, 2023)

  • MICROSOFT 365 Apps for Enterprise Version 16.0.16227.20318

Another server in the same office still has

  • Microsoft Office Professional Plus 2016 Version 16.0.04266.1001 and the same .bat runs successfully with the compiled .pdf as output.

Thus the wordFormatpdf = "17" might need to upgraded to a different number corresponding the the Microsoft Apps package holding word/excel/powerpoint?

0 Answers0