|
- #!/usr/bin/env python
- # coding: utf-8
-
- # In[1]:
-
-
- from PyPDF2 import PdfFileWriter,PdfFileReader
- from reportlab.pdfgen import canvas
- #from StringIO import StringIO
- from io import BytesIO
-
-
- # In[2]:
-
-
- imgPath = "img.png"
-
-
- # In[3]:
-
-
- imgTemp1 = BytesIO()
- imgDoc1 = canvas.Canvas(imgTemp1)
- #imgDoc1.drawImage(imgPath, 397.7, 85, 160, 420)
- imgDoc1.drawImage(imgPath, 394.2, 80, 200, 435) ## at (399,760) with size 160x160
- imgDoc1.save()
-
-
- # In[4]:
-
-
- imgTemp2 = BytesIO()
- imgDoc2 = canvas.Canvas(imgTemp2)
- #imgDoc2.drawImage(imgPath, 397.7, 85, 160, 600)
- imgDoc2.drawImage(imgPath, 394.2, 80, 200, 600)## at (399,760) with size 160x160
- imgDoc2.save()
-
-
- # In[5]:
-
-
- pdf = '../../Downloads/200511-JHO-FICHIER MDPH 95.pdf'
-
-
- # In[6]:
-
-
- readpdf = PdfFileReader(pdf)
-
-
- # In[7]:
-
-
- pdf_ecriture = PdfFileWriter()
-
-
- # In[8]:
-
-
- overlay1 = PdfFileReader(BytesIO(imgTemp1.getvalue())).getPage(0)
- overlay2 = PdfFileReader(BytesIO(imgTemp2.getvalue())).getPage(0)
- for NumPage in range(readpdf.getNumPages()):
- pageObj = readpdf.getPage(NumPage)
- page_content = pageObj.extractText()
- if 'Prestations faites au profit de' not in page_content:
- if 'DÉTAIL' in page_content:
- pageObj.mergePage(overlay1)
- pdf_ecriture.addPage(pageObj)
- #print ("effacement de type 1")
- else:
- #print ("effacement de type 2")
- pageObj.mergePage(overlay2)
- pdf_ecriture.addPage(pageObj)
- else:
- #print ("rien")
- pdf_ecriture.addPage(pageObj)
-
-
- # In[9]:
-
-
- pdf_ecriture.write(open("output_.pdf","wb"))
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
-
-
- # In[ ]:
-
-
-
|