1/72th of an inch

2023-10-20 19:40
文章标签 inch 72th

本文主要是介绍1/72th of an inch,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在根据Android graphics pdf PdfDocument写Android上的PDF demo程序时,其中这一点是编译不过:
这里写图片描述
网上搜索了一下,参数的另一种写法是:

// crate a page description
PageInfo pageInfo = new PageInfo.Builder(595, 842, 1).create();

即这个API:

/*** Creates a new builder with the mandatory page info attributes.** @param pageWidth The page width in PostScript (1/72th of an inch).* @param pageHeight The page height in PostScript (1/72th of an inch).* @param pageNumber The page number.*/
public Builder(int pageWidth, int pageHeight, int pageNumber) {...
}

这里的长度单位写的是「1/72th of an inch」,一时不懂是什么意思,像A4这种标准尺寸一般会有ISO的毫米尺寸210297mm以及英寸长度8.27 in x 11.69 in,那「1/72th of an inch」又是什么呢?试着按照毫米和英寸填写,生成的PDF尺寸都不是A4大小。为了快速了解我以「PageInfo.Builder a4」为关键字在Google上找到了Android - Drawing to a PDF canvas from WebView,这里使用的参数是(595,842,1),我照着填上后生成的PDF确实是A4大小了,如下图:
这里写图片描述
然后经过简单的计算8.27
72=595.44得出了他们之间的关系,这里要填写的数是inch*72。这里iso-paper-sizes也有说明:
这里写图片描述

其实这样直接填数字并不是一个好的方法,这里可以借用PrintAttributes.MediaSize类,这里已经有了很多标准尺寸值。取出其英寸值再进行运算就得出了这里要填写的数了。

// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(PrintAttributes.MediaSize.ISO_A4.getWidthMils() * 72 / 1000,PrintAttributes.MediaSize.ISO_A4.getHeightMils() * 72 / 1000, 1).create();

最后顺便贴一下在Activity中使用的完成Demo程序:

public void onClick(View v) {// create a new documentPdfDocument document = new PdfDocument();// crate a page descriptionPdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(PrintAttributes.MediaSize.ISO_A4.getWidthMils() * 72 / 1000,PrintAttributes.MediaSize.ISO_A4.getHeightMils() * 72 / 1000, 1).create();// start a pagePdfDocument.Page page = document.startPage(pageInfo);// draw something on the pageView content = findViewById(android.R.id.content);;content.draw(page.getCanvas());// finish the pagedocument.finishPage(page);// add more pages// write the document contentFileOutputStream os = null;try {String string = getExternalFilesDir(Environment.DIRECTORY_DCIM)+ File.separator + "test.pdf";Log.i(LOG_TAG, "String:" + string);os = new FileOutputStream(string);document.writeTo(os);os.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {// close the documentdocument.close();}
}

这篇关于1/72th of an inch的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/249324

相关文章

记录:mac pro 16-inch,2019安装ubuntu双系统

需要的装备:u盘,扩展坞、有线键鼠、ext4硬盘 目的:编译aosp 11 1、首先是参照如下文章,分配空间,制作启动盘(测试ubuntu20.04不行,ubuntu22.04正常) https://blog.csdn.net/LBSGKD/article/details/122681929 2、mac关机: 按住 Command + R 开机,进入恢复界面,在 Utilities > St

C算法:米m 转化 英尺foot和英寸inch

需求: 已知1英尺等于12英寸,如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(foot+inch/12)*0.3048,现在,用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢? 输入样例: 170cm 输出样例: 5'6'' 代码实现: #include<stdio.h>int main(){int foot = 0;int inch = 0;float

STM32+2.9inch微雪墨水屏(电子纸)实现显示

本篇文章从硬件原理以及嵌入式编程等角度完整的介绍了墨水屏驱动过程,本例涉及的墨水屏为2.9inch e-Paper V2,它采用的是“微胶囊电泳显示”技术进行图像显示,其基本原理是悬浮在液体中的带电纳米粒子受到电场作用而产生迁移,从而改变显示屏各像素点的颜色。 墨水屏的原理决定了它具有很好的稳定性,如果电场不改变,粒子就不再运动,也不需要耗电,即使断电,墨水屏的画面也能保留,这个特性使其能作为电

Macbook Air(13-inch, Early 2015) 重新安装操作系统

1. 系统信息如下 上次安装 操作系统的时候,硬盘格式化成区分大小写了。导致 Adobe illustrator 安装不上去。这里重新安装一下操作系统。 2. 格式化磁盘为不区分大小写的格式 Intel 处理器 将 Mac 开机并立即按住 Command (⌘)-R,直至你看到 Apple 标志或其他图像。 选择磁盘工具 macos宗卷->右上角抹掉->名称:随便填(最好英文)。格式选

【树莓派/入门】1.69inch LCD屏幕的连接与测试

说在前面 树莓派版本:4bLCD模块:MAX30102树莓派系统:Linux raspberrypi 5.15.76-v8+ #1597 SMP aarch64 GNU/Linuxpython版本:3.9.2买回来发现不是触摸屏,瞎了 模块详情 某雪的1.69inch LCD模块,包含杜邦线 准备工作 某雪的wiki文档还是挺详细的,按着来就行了,就是树莓派的引脚图不太清晰,这里