[英]How can i create landscape PDF using android native PdfDocument API?
I am using PdfDocument API to write a PDF from View using Android 我正在使用PdfDocument API从使用Android的View编写PDF
Problem 问题
If am writing PDF of A4 size. 如果正在编写A4大小的PDF。 How can i make in landscape mode? 如何在横向模式下进行拍摄?
Thanks in Advance. 提前致谢。
A typical use of the Android PDF APIs looks like this: Android PDF API的典型用法如下所示:
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
// start a page
Page page = document.startPage(pageInfo);
// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());
// close the document
document.close();
According to the developer.android.com reference : 根据developer.android.com参考 :
public PdfDocument.PageInfo.Builder (int pageWidth, int pageHeight, int pageNumber)
Added in API level 19 在API级别19中添加
Creates a new builder with the mandatory page info attributes. 创建具有强制页面信息属性的新构建器。
Parameters 参量
pageWidth
The page width in PostScript (1/72th of an inch).pageWidth
页面宽度,以PostScript(1/72英寸)为单位。
pageHeight
The page height in PostScript (1/72th of an inch).pageHeight
PostScript中的页面高度(pageHeight
英寸)。
pageNumber
The page number.pageNumber
页码。
To create a PDF with portrait A4 pages, therefore, you can define the page descriptions like this: 因此,要创建带有A4纵向页面的PDF,可以定义如下页面描述:
PageInfo pageInfo = new PageInfo.Builder(595, 842, 1).create();
and for a PDF with landscape A4 pages, you can define them like this: 对于具有横向A4页面的PDF,可以这样定义它们:
PageInfo pageInfo = new PageInfo.Builder(842, 595, 1).create();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.