2

I have tried merge_page method in pypdf and pdfrw but they stact one page over other, how do I proceed? below code which i tried, similar with both modules

from pdfrw import PdfReader, PdfWriter, PageMerge

def merge_pdf_pages(input_file='input.pdf'):
    # Read the input PDF file
    reader = PdfReader(input_file)
    writer = PdfWriter()
    pages = PageMerge()
    for page in reader.pages:
        pages.add(page)
    writer.addpage(pages.render())
    with open("output.pdf",'wb') as file:
        writer.write(file)
# Example usage
merge_pdf_pages('input.pdf')
V Falcon
  • 25
  • 4
  • What you are trying to do is called "imposition", if that helps. And no, it can't be done just by byte manipulation - PDF files don't work like that. – johnwhitington Jul 27 '23 at 21:25

1 Answers1

1

Blending multiple PDF into a single sheet is usually done by trained Graphics Artist, who understand the programming problems related to computerised PDF design.

Compositors or Imposers will fine tune an "Imposition" or "Composition" using more than one simple method, but in effect it is simply reprint at a different scale (or same scale)

Here I can graphically adjust the most basic of such "N-UP" methods in a Browser PDF reader, but the complexity will be similar using a single programmed command line.

Most complex might be 40 pages as Ten Plates where matrix calculations would be used for "Booklet" production in LaTeX using folds, slits and bleed boxes

enter image description here

When designing programs for Desk Top "Publications" the maths can be complex, yet simply repetitive using boilerplates. https://tex.stackexchange.com/a/490408

Since you have given few clues in the question? I have to presume from "one over the other" that means 2 landscape on 1 portrait enter image description here

The difference between a Program and a Human Composer can be seen here. The Programmatic result is on the Left to Right However the Human Viewer will set those Four sheets via the R2L settings.

enter image description here

From comments it was stated the desire is to emulate, output same as continuous view.
Here on the left we see pages as normally spaced out in the viewer, where in the middle view, the PDF viewer can use "continuous page mode" (with seamless spacing, but still 4 controllable pages) and on the right the output from imposing infinite pages vertically.

enter image description here

In this case the command used was

cpdf -impose-xy "1 0" fourL.pdf -o Output.pdf

where cpdf is a cross platform application for binary command line applications or I believe with a JavaScript API/SDK interface and one for Python (pycpdflib). See https://github.com/coherentgraphics

specifically (link may become outdated, but currently) https://www.coherentpdf.com/cpdfmanual/cpdfmanualch9.html#x13-860009.2

K J
  • 8,045
  • 3
  • 14
  • 36
  • In Fourl.pdf output page, 1 and 2 are merged seamlessly, I wanted that behavior but vertically and all of the pages have to be merged into a single seamless page. And you are suggesting this cant be done by conventional programming techniques? – V Falcon Jul 28 '23 at 05:36