将一个PDF页面拆分为两个 [英] Split one PDF page into two

查看:646
本文介绍了将一个PDF页面拆分为两个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个宽PDF页面分成两个PDF页面。我的原始页面宽两个A4页面大小但高度正常(对于A4)。我试图使用IText但没有效果。感谢您的关注。

i want to split one wide PDF page into two PDF pages. My original page is wide as two A4 page size but height is normal(for A4). I trying to use IText but with no effects. Thanks for attention.

推荐答案

我不知道iText API,但您可以按照以下步骤前往:

I don't know the iText API, but you can follow these steps to get there:

创建现有页面的两个新副本。这意味着您拥有相同的资源,相同的ContentStream等。

Create two new copies of the existing page. This means that you have the same Resources, the same ContentStream, etc.

获取第一页的MediaBox,这是一个列为[llx lly urx ury]的数组。

Get the MediaBox for the first page which is an array laid out as [llx lly urx ury].

if MediaBox[2] - MediaBox[0] == long edge of A4 page then
    HalfPageWidth = MediaBox[2] - MediaBox[0];
    PageCopy1.CropBox = [MediaBox[0] MediaBox[1] (MediaBox[0] + HalfPageWidth) MediaBox[3]]
    PageCopy2.CropBox = [(MediaBox[0] + HalfPageWidth) MediaBox[1] MediaBox[2] MediaBox[3]]
else
    HalfPageHeight = MediaBox[3] - MediaBox[1];
    PageCopy1.CropBox = [MediaBox[0] MediaBox[1] MediaBox[2] (MediaBox[1] + HalfPageHeight)]
    PageCopy2.CropBox = [MediaBox[0] (MediaBox[1] + HalfPageHeight)] MediaBox[2] MediaBox[3]]

删除原始页面并保存这两页。基本上,您正在制作两个相同的页面副本,并将每个页面裁剪为一半。您可能还需要设置页面旋转。

Remove the original page and save these two pages. Basically, you're making two identical copies of the page and cropped each to half the page. You may also need to set the page rotation.

这篇关于将一个PDF页面拆分为两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆