作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经尝试过代码
@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data)
{
switch (requestCode)
{
case 10:
if (resultCode==RESULT_OK)
{
String path = data.getData().getPath();
path_disp.setText(path);
File file = new File(path);
PdfDocument pdf = new PdfDocument(file.getAbsolutePath(), null);
}
break;
}
}
但这给了我一个错误“PdfDocument 中的 PdfDocument() 无法应用于 (java.lang.String , null)”
最佳答案
https://developer.android.com/reference/android/graphics/pdf/PdfDocument
看起来 PdfDocument 类没有可以接受字符串的构造函数。
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 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();
您必须先创建一个页面,然后才能在 Canvas 上绘制一些内容。在你的情况下,它将是
yourCanvas.drawText("Your string.")
关于java - 我想在 Android Studio 中将文件类型转换为 PdfDocument 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58972473/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!