-1

is ther anyway i can find Coordinates in Python from Objects of the PDF. I want then to Cut the PDf exact above the highest Object and below the lowest Object:

from PyPDF2 import PdfFileWriter, PdfFileReader

with open("in.pdf", "rb") as in_f:
input1 = PdfFileReader(in_f)
output = PdfFileWriter()

numPages = input1.getNumPages()
print ("document has %s pages." % numPages)

for i in range(numPages):
    page = input1.getPage(i)
    print (page.cropBox.getLowerLeft())
    print (page.cropBox.getUpperRight())
    page.cropBox.setLowerLeft((0, 500))
    page.cropBox.setUpperRight((595.275, 841.889))
    output.addPage(page)

with open("out.pdf", "wb") as out_f:
    output.write(out_f)

So the Code now vuts something but yeah how do i find out exactly where to Cut! is ther a Methode?

Edit:

@BhavyaParikh.

I want an alogorithem that finds the Y-Coordinates from the highest and the lowest point of any object given in the pdf page. and then cuts at these points instead of the hardcoded values "(0, 500) and (595.275, 841.889)". So for example: "(x1,y1) and (x2,y2). But i dont know how to finde these Coordinates.

Jayklops
  • 1
  • 2
  • Where to cut means you want `(0, 500)` and `(595.275, 841.889)` passed in function not as hardcoded values – Bhavya Parikh Nov 30 '21 at 13:07
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 04 '21 at 21:30
  • @BhavyaParikh. yes thats what i meen i want an alogorithem that finds the Y-Coordinates from the highest and the lowest point of any object given in the pdf page. and then cuts at these points instead of the hardcoded values "(0, 500) and (595.275, 841.889)". So for example: "(x1,y1) and (x2,y2). But i dont know how to finde these Coordinates. – Jayklops Dec 06 '21 at 06:10

1 Answers1

0

you can pass crop data to function it self by assigning as variable

    x1=page.cropBox.getLowerLeft()
    x2=page.cropBox.getUpperRight()
    page.cropBox.setLowerLeft(x1)
    page.cropBox.setUpperRight(x2)
Bhavya Parikh
  • 3,304
  • 2
  • 9
  • 19
  • thats what i did at first but the cropbox is the pagesize for my pdfs, but i want to cut the whitespace around my objects. so i f i do you suggestion i end up with the page as it was – Jayklops Dec 09 '21 at 07:58