我想将一个宽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页面拆分为两个
发布评论