Commit 26dfacb6 authored by Amrita Deb's avatar Amrita Deb
Browse files

Merge branch 'ad_latest' into 'master'

Remove PyPDF2 dependancies-using pikepdf to combine PDFs

See merge request !23
parents fb360bb0 280ebd5b
......@@ -16,7 +16,8 @@ from multiprocessing import Pool # multi processing
from functools import partial
from wand.image import Image as wi # PDF to images
from PIL import Image, ImageDraw, ImageFont # Image handling
from PyPDF2 import PdfFileMerger, PdfFileReader # PDF handling
from pikepdf import Pdf #combining PDFs
from glob import glob #combining PDFs
import utils.matnum as utils
......@@ -148,12 +149,12 @@ def combine_all_pdfs(pdf_pages, out_dir):
Returns:
str: path to combined PDF
"""
# Merge single pages to one PDF
mergedObject = PdfFileMerger()
# mergedObject = PdfFileMerger()
mergedObject = Pdf.new() # create a blank PDF
for pdf_page in pdf_pages:
mergedObject.append(PdfFileReader(pdf_page, 'rb'))
os.remove(pdf_page)
src = Pdf.open(pdf_page)
mergedObject.pages.extend(src.pages)
# Create file name of merged PDF
pdf_name = os.path.basename(pdf_pages[0]) # remove full path
......@@ -162,7 +163,7 @@ def combine_all_pdfs(pdf_pages, out_dir):
pdf_file = out_dir+'/'+pdf_name+'_w.pdf'
# Save merged PDF
mergedObject.write(pdf_file)
mergedObject.save(pdf_file)
return pdf_file
......@@ -203,6 +204,8 @@ def watermark_pdf(input_dir, tmp_dir, output_dir, dpi, pdf_file):
else:
raise Exception("{}: No PDF pages found".format(pdf_file))
for pdf_file in pdf_files:
os.remove(pdf_file)
return watermarked_pdf
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment