简体   繁体   English

更改现有PDF文档的方向(纵向/横向)

[英]Change orientation of existing PDF document (portrait/landscape)

Is it possible to change the orientation of an existing document from 'portrait' to 'landscape' or vise versa? 是否可以将现有文档的方向从“纵向”更改为“横向”,反之亦然?

I've tried copying a page (in portrait mode) to a newly created page (in landscape mode) using iText but it didn't work, the page orientation of the copied page was used. 我尝试使用iText将页面(纵向模式)复制到新创建的页面(横向模式),但是它不起作用,使用了复制页面的页面方向。

Here's the code I used: 这是我使用的代码:

PdfReader originalFileReader = new PdfReader(src);

Document landscapeDoc = new Document(PageSize.A4.rotate());

PdfCopy copy = new PdfCopy(landscapeDoc, new FileOutputStream("/home/user/landscape.pdf"));

landscapeDoc.open();

for (int i = 1; i <= originalFileReader.getNumberOfPages(); i++) {
     copy.addPage(copy.getImportedPage(originalFileReader, i));
}

landscapeDoc.close();

Getting a page from the original file and adding it to the copy doesn't re-layout the page. 从原始文件获取页面并将其添加到副本不会重新布局页面。 If you get a landscape page at all, it will simply contain a copy of the original page clipped to the height of the landscape page. 如果您完全得到一个横向页面,它将仅包含原始页面的副本,该副本被剪裁为横向页面的高度。

Looking at the iText site it appears that the 2 closest use-cases to what you want are extracting data fields (marked up using a template) from a PDF to an XML structure ( pdf2Data ) and adding content (watermarks, images, annotations, etc.) to an existing PDF. iText网站上 ,似乎最接近您想要的两个用例是将数据字段(使用模板标记)从PDF提取到XML结构( pdf2Data )并添加内容(水印,图像,注释等) 。)到现有的PDF。 (Lots of examples here .) 这里有很多例子。)

There's nothing there about intelligently pulling content and formatting from a PDF and re-laying it out in a different PDF. 关于智能地从PDF提取内容和格式并将其重新布局到其他PDF中,没有任何内容。 (Which would be an extremely hard problem anyway.) (无论如何,这将是一个极其困难的问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM