我已经try 了pypdf和pdfrw中的merge_page方法,但它们使一个页面比另一个页面停滞,我该如何继续? 下面是我try 过的代码,与这两个模块类似

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')

我的目标是将所有PDF内容合并成一个大页面,这样我就可以制作大小相等的小页面块,因为我不能合并,我已经实现了后来的逻辑.以下样式仍未完成,仅供参考

    pdf = PdfReader(input_file)
    writer = PdfWriter()
    for page in pdf.pages:
        _mb = page.mediabox
        width = _mb.width
        while True:
            _mb.bottom = max(_mb.top-max_dim_val,0)    
            #--------------------------------------------------
            if width > max_dim_val:
                # width split for each height split
                _mb.right = 0
                while True:
                    _mb.right = min(_mb.right+max_dim_val,width)
                    writer.add_page(page)
                    if _mb.left+max_dim_val <= width:
                        _mb.left += max_dim_val
                    else:
                        _mb.left = _mb.right = 0
                        break
            #--------------------------------------------------
            else:writer.add_page(page)
            if _mb.top >= max_dim_val:
                _mb.top -= max_dim_val
            else:break
    with open("output.pdf",'wb') as file:
        writer.write(file)

我基本上已经try 了所有的方法,有没有一种方法可以通过操作文件字节来实现?

推荐答案

将多个PDF混合到一张纸中通常是由训练有素的图形艺术家完成的,他们了解与计算机化PDF设计相关的编程问题.

合成者或抄写者会使用不止一种简单的方法来微调拼版或合成,但实际上它只是以不同的比例(或相同的比例)重印.

在这里,我可以在浏览器PDF阅读器中以图形方式调整这种"N-up"方法中最基本的方法,但使用单个编程命令行的复杂性将是相似的.

最复杂的可能是40页作为10个板材,其中矩阵计算将用于使用折叠、缝隙和出血盒在latex 中生产"小册子"

enter image description here

当为桌面"出版物"设计程序时,数学计算可能很复杂,但使用样板程序却很简单.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

程序和人类composer 之间的区别可以在这里看到.编程结果显示在从左到右的位置,但人工查看器将通过R2L设置设置这四张纸.

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

在本例中,使用的命令是

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

其中,cpdf是一个针对二进制命令行应用程序的跨平台应用程序,我相信它具有一个JavaScript API/SDK接口和一个用于Python(pycpdflib)的接口.见https://github.com/coherentgraphics

Python-3.x相关问答推荐

Python避免捕获特定异常

估计列表中连续对的数量

Python base64.b32hexencode 未创建预期结果

Pytest顺序测试A,然后测试B,然后再测试A

pytorch 中 mps 设备的 manual_seed

如何使用复选按钮更改 Pyplot 轴的属性?

删除给定数组中所有元素为True的所有子数组

为列表列表中的每个列表插入 str 到 index[0] 中. Python

在 Django 中执行 JSONRenderer.render(serialized_student_data.data) 时遇到问题

在不使用字符串方法的情况下查找字符串最后一个单词的长度 - Python

从 yahoo Finance python 一次下载多只股票

为什么包含类的名称不被识别为返回值函数注释?

pysftp vs. Paramiko

使用 Sympy 方程进行绘图

Python图例属性错误

迭代dict值

Selenium (Python) - 使用 Chrome 网络驱动程序等待下载过程完成

ImportError:无法导入名称cross_validate

每次启动 Google Colab 时都必须安装所需的软件包吗?

如何创建一个永远在其上运行滚动协程的事件循环?