gpt4 book ai didi

java - 我想在 Android Studio 中将文件类型转换为 PdfDocument 类型

转载 作者:行者123 更新时间:2023-12-01 20:08:49 25 4
gpt4 key购买 nike

我已经尝试过代码

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com