如何将页面旋转为横向,页面内容应为纵向iTextpdf [英] how to rotate pages into landscape and page content should be in portrait iTextpdf

查看:669
本文介绍了如何将页面旋转为横向,页面内容应为纵向iTextpdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个PDF文档,该文档具有超过2页的纵向页面和横向的其他页面,我发现页面和文本都旋转为横向,我需要防止页面内容旋转.正在使用以下代码

I'm trying to create a PDF document with more than 2 pages in portrait and others in landscape, I found that both page and text rotates to landscape I need to prevent page content rotation. am using following code

 Document document = new Document(PageSize.A4, 36, 36, 36, 72);
    PdfWriter writer = PdfWriter.getInstance(document, new 
    FileOutputStream(outPutDirectory + indexID + ".pdf"));
    writer.setPageEvent(new Orientation(orientation));
    document.open();
    XMLWorkerHelper.getInstance().parseXHtml(writer,document, new ByteArrayInputStream(parserXHtml(page.getPageContent()).getBytes()))
    document.close();

我的预期结果应该是这样

my expected result should be like this

推荐答案

您不必更改页面事件,而必须更改页面大小.

Instead of using a page event, you have to change the page size.

例如:

Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream(outPutDirectory + indexID + ".pdf"));
document.open();
// Add some content in portrait
document.setPageSize(PageSize.A4.rotate());
document.newPage();
// Add some content in landscape
document.close();

请注意以下事实:页面大小仅在下一页上改变. setPageSize()newPage()的顺序很重要.

Be aware of the fact that the page size only changes on the next page. The order of setPageSize() and newPage() is important.

这篇关于如何将页面旋转为横向,页面内容应为纵向iTextpdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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