使用外部应用程序以编程方式编辑pdf [英] Edit pdf with external application programatically

查看:131
本文介绍了使用外部应用程序以编程方式编辑pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求让我的应用程序编辑PDF文件.因为发现很难集成到应用程序中,所以我决定使用外部应用程序,并决定使用

I have a request to make my application edit PDF files. Because I found it hard to integrate into the application, I decided to go with the external app and decided to use Xodo reader.

我遇到的问题是,当我在Xodo应用程序中打开pdf并对其进行编辑时,它没有保存到其原始位置,而是将副本保存到了Download文件夹中.对我来说,这表明该应用程序无法将编辑后的文件保存回其原始目的地,我相信这是因为我没有正确执行操作.

The problem I am having is that when my pdf is opened in the Xodo app and edited, it's not being saved to its original location, but rather a copy is saved to the Download folder. To me, this indicates that the app isn't able to save the edited file back to it's original destination, and I believe it's because I didn't do something right.

我为什么这么认为?

当Xodo应用程序打开一个.pdf文件,然后在我回击时对其进行编辑时,会将其保存到从中打开的内存位置.当我用我的应用程序加载它时,它就无法正常工作.

When Xodo app opens a .pdf file and then edits it when I hit back it saves it to the memory location it is opened from. When I load it with my app, it doesn't work that way.

这是我的代码:

我如何调用应用程序

    val target = view?.packageManager?.getLaunchIntentForPackage("com.xodo.pdf.reader")
    target?.action = Intent.ACTION_EDIT
    target?.setDataAndType(FileProvider.getUriForFile(context, view?.applicationContext?.packageName + ".fileprovider", report.file), "application/pdf")
    target?.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
    target?.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION

    view?.startActivity(target)

我的@ xml/provider_paths是什么样的

<paths xmlns:android="http://schemas.android.com/apk/res/android">
     <external-path name="myApp" path="."/>
</paths>

我的文件在内存中的位置

/内部存储/myApp

/Internal storage/myApp

我的内容URI是什么样的

content://com.example.myapp.debug.fileprovider/myApp/myApp/example0.pdf

content://com.example.myapp.debug.fileprovider/myApp/myApp/example0.pdf

有人知道我在做什么错吗?在哪里?

Does anybody have a clue what I am doing wrong and where?

推荐答案

尝试同时授予FLAG_GRANT_READ_URI_PERMISSIONFLAG_GRANT_WRITE_URI_PERMISSION.目前,您只授予读取访问权限,因此Xobo无法写回提供程序.

Try granting both FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION. Right now, you are only granting read access, and so Xobo has no ability to write back to the provider.

请注意,没有任何要求 Xobo可以写回提供程序,因此,即使您授予写访问权限,Xobo仍可能会将修改后的PDF写到单独的文件中.

Note that there is nothing that requires Xobo to write back to the provider, so even if you grant write access, Xobo may still write the modified PDF to a separate file.

这篇关于使用外部应用程序以编程方式编辑pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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