在Android上从Webview保存PDF

在Android上从Webview保存PDF,第1张

概述我想将我的webview保存为PDF文件.我知道我可以使用WebView.createPrintDocumentAdapter()和PrintManager.print()打印WebView. 但我需要一种方法来保存PDF,这是由PrintDocumentAdapter内部生成的,没有任何用户交互,因为我需要该文件在我的应用程序内进一步处理. 有任何想法吗? 我意识到这个问题现在已经很老了.但我刚 我想将我的webvIEw保存为pdf文件.我知道我可以使用WebVIEw.createPrintdocumentAdapter()和PrintManager.print()打印WebVIEw.
但我需要一种方法来保存pdf,这是由PrintdocumentAdapter内部生成的,没有任何用户交互,因为我需要该文件在我的应用程序内进一步处理.

有任何想法吗?

解决方法 我意识到这个问题现在已经很老了.但我刚刚意识到如何做到这一点.

基本上根据问题,您可以使用上面提到的createPrintdocumentAdapter方法并将结果传递给您自己的“假”PrintManager实现,该实现只是覆盖onWrite方法以将输出保存到您自己的文件中.下面的代码段显示了如何获取任何PrintdocumentAdapter并将其输出发送到文件.

public voID print(PrintdocumentAdapter printAdapter,final file path,final String filename) {    printAdapter.onLayout(null,printAttributes,null,new PrintdocumentAdapter.LayoutResultCallback() {        @OverrIDe        public voID onLayoutFinished(PrintdocumentInfo info,boolean changed) {            printAdapter.onWrite(null,getoutputfile(path,filename),new CancellationSignal(),new PrintdocumentAdapter.WriteResultCallback() {                @OverrIDe                public voID onWriteFinished(PageRange[] pages) {                    super.onWriteFinished(pages);                }            });        }    },null);}

正如您所看到的那样,在适配器方法中传递了相当多的空值,但我检查了Chromium源代码,并且从未使用过这些变量,因此空值正常.

我在这里创建了一篇关于如何做到这一点的博文:
http://www.annalytics.co.uk/android/pdf/2017/04/06/Save-PDF-From-An-Android-WebView/

总结

以上是内存溢出为你收集整理的在Android上从Webview保存PDF全部内容,希望文章能够帮你解决在Android上从Webview保存PDF所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125338.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存