如何旋转页面而不是iText中的文本? [英] how to rotate pages but not the text in iText?

查看:131
本文介绍了如何旋转页面而不是iText中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个PDF文档,其中某些页面为纵向页面,另一些页面为横向页面,但是看到了此示例(

I'm trying to create a PDF document with some pages in portrait and others in landscape, but seeing this example (iText7 - Page orientation and rotation) I found that the page rotates to landscape but the text also does it (PDF generated from iText7 samples), then, I need that the pages to rotate but the text continues from left to right, how in the next image.

注意:我尝试使用document.getPdfDocument().addNewPage(new PageSize(PageSize.A4.rotate()));,但是它只能用于一页,而不能用于接下来的x页.

Note: I tried to use document.getPdfDocument().addNewPage(new PageSize(PageSize.A4.rotate()));but it works for one page, not for the next x pages.

推荐答案

您可以通过设置页面大小来实现

You can do it with setting page size

对于itextpdf 5.5.x

Document doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("D://qwqw12.pdf"));
doc.open();
doc.add(new Paragraph("Hi"));
doc.setPageSize(PageSize.A4.rotate());
doc.newPage();
doc.add(new Paragraph("Hi2"));
doc.newPage();
doc.add(new Paragraph("Hi3"));
doc.close();

这将创建一个带有 Hi 的A4页面,然后一个带有 Hi2 Landscape-取向页面,最后一个页面也将是以景观为导向.除非您没有通过setPageSize()设置新的页面样式,否则所有新页面都将以横向显示.

this will create an A4-page with Hi, then an landscape-oriented page with Hi2, and last page will also be landscape-oriented. All new pages will be landscape-oriented until you don't set new page style via setPageSize().

对于itextpdf 7.x

PdfDocument pdfDoc = new PdfDocument(new PdfWriter("D://qwqw12.pdf"));
Document doc = new Document(pdfDoc, PageSize.A4);
doc.add(new Paragraph("Hi"));
doc.getPdfDocument().setDefaultPageSize(PageSize.A4.rotate());
doc.add(new AreaBreak());
doc.add(new Paragraph("Hi2"));
doc.add(new AreaBreak());
doc.add(new Paragraph("Hi3"));
doc.close();

这篇关于如何旋转页面而不是iText中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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