0

I have two PDF file,My problem is read two pdf file and covert to image file. I want to add blank pages to the end of the PDF which has less number of pages, so that the number of pages in both PDFs is same. My question is how to compare and add blank pages to the PDF using python? Any pointers on this would be helpful.

list_im = []
images = convert_from_path(r"/home/hp/PycharmProjects/DHT/pdf_comparison/pdf/project plan1-2.pdf")
for i in range(len(images)):
    min_shape = sorted([(np.sum(i.size), i.size) for i in images])[0][1]
    imgs_comb_1 = np.hstack((np.asarray(i.resize(min_shape)) for i in images))
    imgs_comb_1 = np.vstack((np.asarray(i.resize(min_shape)) for i in images))


images = convert_from_path(r"/home/hp/PycharmProjects/DHT/pdf_comparison/pdf/project plan1-1.pdf")
for i in range(len(images)):
    min_shape = sorted([(np.sum(i.size), i.size) for i in images])[0][1]
    imgs_comb_2 = np.hstack((np.asarray(i.resize(min_shape)) for i in images))
    imgs_comb_2 = np.vstack((np.asarray(i.resize(min_shape)) for i in images))
  • 1
    It seems like you have two questions: how to add a blank page to the end of the PDF, and how to find out how many pages are in it already. Both of those sound to me like [research](https://meta.stackoverflow.com/questions/261592) questions, that will depend on the library you are using to handle the PDF files. That said: do I understand correctly, that you get one image created from each page in the PDF? In that case, I think you already know how to count the pages. (Hint: how many times will `for i in range(len(images)):` run? How do you know?) – Karl Knechtel Jul 01 '22 at 07:53
  • yes im able to check the pdf length, but how to add blank pages to the PDF using python? –  Jul 01 '22 at 07:57
  • 1
    @janedoe you can use `pypdf2` which has an `add_blank_page` function: https://pypdf2.readthedocs.io/en/latest/modules/PdfWriter.html#PyPDF2.PdfWriter.add_blank_page – M B Jul 01 '22 at 07:58
  • "but how to add blank pages to the PDF using python?" Well, are you able to write new PDFs at all? What actually is the purpose of the code to assign `min_shape` and `imgs_comb_1`? – Karl Knechtel Jul 01 '22 at 08:00

0 Answers0