【问题标题】:how android use BlueTooth printer print the WebView contentandroid如何使用蓝牙打印机打印WebView内容
【发布时间】:2016-12-15 03:12:35
【问题描述】:

如何使用带有 android 的蓝牙打印机打印 HTML?我可以打印 String=" 你得了 192 分。"进入html页面?

【问题讨论】:

  • 您可以轻松地将整个 html 页面打印为字符串。但是如果你想保留html页面的格式,即缩进,那么你必须在打印时手动处理它。
  • 我要打印html页面,怎么办?

标签: android html printing bluetooth


【解决方案1】:

在 Android 开发者网站上有一个关于打印 WebView 内容的快速方法:

来自https://developer.android.com/training/printing/html-docs.html

// Get a PrintManager instance
PrintManager printManager = (PrintManager) getActivity()
        .getSystemService(Context.PRINT_SERVICE);

// Get a print adapter instance
PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

// Create a print job with name and adapter instance
String jobName = getString(R.string.app_name) + " Document";
PrintJob printJob = printManager.print(jobName, printAdapter,
        new PrintAttributes.Builder().build());

您甚至不必先显示 WebView - 事实上,他们建议您使用专用的不可见 WebView 进行打印。

不过,要打印到蓝牙打印机,您需要安装该打印机的打印服务应用程序,或使用制造商特定的 SDK - 两者都可能不存在 :(

【讨论】:

  • 请在您的答案中包含来自包含链接的相关信息
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
  • 1970-01-01
  • 2011-12-28
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多