Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDF Manipulation
#6
(Oct-16-2023, 02:13 AM)9156088686 Wrote: I waited for the code to finish it errored out and returned this.
Probably the error message is a bit longer, but it looks obvious, you seem to do it all in memory.
I do loads of these, and I have no memory problems, because I physically save every page
as a png. As I mentioned in my previous post, once you swapped the 1/3 and the 2/3 to a new image,
you could convert all these new images into a pdf an delete the intermediate pngs.
pngs allow you to immediately find the number of pixels (x and y) via PIL, Image, as you do.
Directly, not via the DPI (dots per inch) detour , which should be ppi, by the way (pixels per inch).
Here is my code to slice a pdf into separate images, that are easily manipulated.
for pdffile in glob.glob(pdf_path + '\*.pdf'): 
        doc = fitz.open(pdffile)
        zoom = 4
        mat = fitz.Matrix(zoom, zoom)
        count = 0
        # Count variable to get the number of pages in the pdf
        for p in doc:
            count += 1
        for i in range(count):
            img= os.path.join(os.curdir,'data',f'scan-{str(i+1)}.png')
            page = doc.load_page(i)
            pix = page.get_pixmap(matrix=mat)
            pix.save(img)
        doc.close()
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
PDF Manipulation - by 9156088686 - Sep-27-2023, 09:27 PM
RE: PDF Manipulation - by DPaul - Sep-28-2023, 05:43 AM
RE: PDF Manipulation - by 9156088686 - Sep-28-2023, 08:24 PM
RE: PDF Manipulation - by DPaul - Sep-29-2023, 07:57 AM
RE: PDF Manipulation - by 9156088686 - Oct-16-2023, 02:13 AM
RE: PDF Manipulation - by DPaul - Oct-16-2023, 06:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020