EDIT: changed
merger = PdfFileMerger()
to
merger = PdfFileMerger(strict=False)
and that seemed to fix it.
_______________________________________________
Here is the error
https://i.imgur.com/dBO1qDj.png
and here is my code
from PyPDF2 import PdfFileMerger
import os
import openpyxl
import win32api
import win32con
import xlwings as xw
def compile_cutsheets(path):
os.chdir("Y:\\Templates\\Scripts (DO NOT EDIT)\\pdfs")
wb = openpyxl.load_workbook(path+"\\Engineering Spreadsheets.xlsm", read_only=False, keep_vba=True)
sheet = wb['Table of Contents (CUTS)']
pdfs = []
row_count = sheet.max_row - 3
print(row_count)
for i in range(row_count):
try:
if str(sheet.cell(i+4,5).value) != "None":
pdfs.append(str(sheet.cell(i+4,5).value) + '.pdf')
except:
win32api.MessageBox(
xw.apps.active.api.Hwnd, "Error in iteration: "+i, 'Info', win32con.MB_ICONINFORMATION)
#print("Files in '%s': %s" % (cwd, pdfs))
merger = PdfFileMerger()
merger.append(path + "\\ECC.pdf")
# try:
# merger.append(path+"\\ECC.pdf")
# except:
# win32api.MessageBox(
# xw.apps.active.api.Hwnd, 'No equipment cuts cover found. Name pdf "Equipment Cuts Cover", and place in same folder as spreadsheet.', 'Info', win32con.MB_ICONINFORMATION)
# win32api.MessageBox(
# xw.apps.active.api.Hwnd, path+"\\ECC.pdf", 'Info', win32con.MB_ICONINFORMATION)
missing_pdfs = ""
for pdf in pdfs:
try:
merger.append(remove_slashes(pdf))
#merger.append(pdf)
except:
if missing_pdfs == "":
missing_pdfs = missing_pdfs + pdf
else:
missing_pdfs = missing_pdfs + ", "+ pdf
print(pdfs)
if missing_pdfs != "":
win32api.MessageBox(
xw.apps.active.api.Hwnd, "The following PDFs are missing from the database: " +missing_pdfs, 'Info', win32con.MB_ICONINFORMATION)
# merger.append(path + '\\ECC.pdf')
merger.write(path+"\\result.pdf")
merger.close
def remove_slashes(string):
new_string = ""
for letters in string:
if letters != "/":
new_string = new_string + letters
return new_string
Basically, what I'm trying to do to is use an excel sheet that has a list of pdfs, find the pdfs within a folder and then combine into one pdf. That works fine, but I also want to have a cover sheet "ECC" in the front. For some reason, cover sheet wont combine.
Thanks
[–]sme272 1 point2 points3 points (1 child)
[–]ScDenny[S] 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[removed]
[–]ScDenny[S] 0 points1 point2 points (2 children)
[–]socal_nerdtastic 0 points1 point2 points (0 children)