Split each PDF page in two?

后端 未结 10 2107
天命终不由人
天命终不由人 2021-01-30 11:39

I have a large number of PDF files which have two slides to a page (for printing).

The format is A4 pages each with two slides setup like so:

-----------         


        
相关标签:
10条回答
  • 2021-01-30 11:54

    With mupdf-1.8-windows-x64, in win10 CMD, you need to have 'poster ' (followed by space and without quotes) before the horizontal parameter (-x ). For example for a double-paged scan to PDF:

    mutool poster -x 2 -y 1 C:\Users\alfie\Documents\SNM\The_Ultimate_Medicine.pdf C:\Users\alfie\Documents\ebooks\The_Ultimate_Medicine.pdf

    What a wonderful tool! Merci infiniment !.. (and the output file ~9MB is only 52KB bigger than the original!)

    0 讨论(0)
  • 2021-01-30 11:57

    Thanks to Matt Gumbley for his Python Script. I have modified that Python script such that it now also works with PDFs that contain portrait and landscape pages and cropped pages:

    # -*- coding: utf-8 -*-
    """
    Created on Thu Feb 26 08:49:39 2015
    
    @author: Matt Gumbley  (stackoverflow)
    changed by Hanspeter Schmid to deal with already cropped pages
    """
    
    import copy
    import math
    from PyPDF2 import PdfFileReader, PdfFileWriter
    
    def split_pages2(src, dst):
        src_f = file(src, 'r+b')
        dst_f = file(dst, 'w+b')
    
        input = PdfFileReader(src_f)
        output = PdfFileWriter()
    
        for i in range(input.getNumPages()):
            # make two copies of the input page
            pp = input.getPage(i)
            p = copy.copy(pp)
            q = copy.copy(pp)
    
            # the new media boxes are the previous crop boxes
            p.mediaBox = copy.copy(p.cropBox)
            q.mediaBox = copy.copy(p.cropBox)
    
            x1, x2 = p.mediaBox.lowerLeft
            x3, x4 = p.mediaBox.upperRight
    
            x1, x2 = math.floor(x1), math.floor(x2)
            x3, x4 = math.floor(x3), math.floor(x4)
            x5, x6 = x1+math.floor((x3-x1)/2), x2+math.floor((x4-x2)/2)
    
            if (x3-x1) > (x4-x2):
                # horizontal
                q.mediaBox.upperRight = (x5, x4)
                q.mediaBox.lowerLeft = (x1, x2)
    
                p.mediaBox.upperRight = (x3, x4)
                p.mediaBox.lowerLeft = (x5, x2)
            else:
                # vertical
                p.mediaBox.upperRight = (x3, x4)
                p.mediaBox.lowerLeft = (x1, x6)
    
                q.mediaBox.upperRight = (x3, x6)
                q.mediaBox.lowerLeft = (x1, x2)
    
    
            p.artBox = p.mediaBox
            p.bleedBox = p.mediaBox
            p.cropBox = p.mediaBox
    
            q.artBox = q.mediaBox
            q.bleedBox = q.mediaBox
            q.cropBox = q.mediaBox
    
            output.addPage(q)
            output.addPage(p)
    
    
        output.write(dst_f)
        src_f.close()
        dst_f.close()
    
    0 讨论(0)
  • 2021-01-30 12:04

    PDF Scissors allowed me to bulk split (crop) all pages in a PDF.

    0 讨论(0)
  • 2021-01-30 12:04

    If using a Java or .Net library is ok for you, you can use iText / iTextSharp.

    An example for tiling an existing document can be found in the book iText in Action, 2nd edition, in the freely available chapter 6: TilingHero.java / TilingHero.cs.

    0 讨论(0)
提交回复
热议问题