简体   繁体   English

使用Delphi从Android设备打印报告

[英]Print reports from Android device using Delphi

I am developing an app using Delphi XE8 and I need to print a report. 我正在使用Delphi XE8开发应用程序,我需要打印报告。

The report has more pages so I can't create a simple image and share it. 该报告有更多页面,所以我无法创建简单的图像并共享它。

The idea is to use the FMX.Printer. 这个想法是使用FMX.Printer。

But the TPrintDialog works only on Windows not on Android. 但是TPrintDialog仅在Windows上不能在Android上使用。 How can I select a printer from the Cloud Print list? 如何从“云打印”列表中选择打印机?

Do you have any suggestions? 你有什么建议吗?

Thanks 谢谢

If the official Google Cloud Print app is installed on the device, then you should be able to access it with an Intent as described in the answer to this question: Print Intent for Google Cloud Print App 如果设备上安装了官方的Google Cloud Print应用程序,那么您应该能够按照此问题的答案中所述的意图来访问它: Google Cloud Print App的打印意图

Intent printIntent = new Intent(Intent.ACTION_SEND);
printIntent.setType("text/html");
printIntent.putExtra(Intent.EXTRA_TITLE, "some cool title for your document");
printIntent.putExtra(Intent.EXTRA_STREAM, uri);

startActivity(printIntent);

I guess that Android then will show a dialog with the available options, including the Cloud Print printers. 我猜想Android随后会显示一个包含可用选项的对话框,包括“云打印”打印机。

Google Cloud Print documentation: https://developers.google.com/cloud-print/docs/android Google云打印文档: https : //developers.google.com/cloud-print/docs/android

API to retrieve the printer list: https://developers.google.com/cloud-print/docs/proxyinterfaces#list 检索打印机列表的API: https : //developers.google.com/cloud-print/docs/proxyinterfaces#list

Putting this into Delphi should look something like: 将其放入Delphi应该看起来像:

uses
...
  FMX.Platform.Android,
  Androidapi.Helpers,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.Embarcadero,
...

var
  printIntent: JIntent;
begin
  printIntent := TJIntent.Create;
  printIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
  printIntent.setType(StringToJString('text/html'));
  printIntent.putExtra(TJIntent.JavaClass.EXTRA_TITLE, StringToJString('Testing print from Android'));
  printIntent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, StringToJString(uri));
  if MainActivity.getPackageManager.queryIntentActivities(printIntent, TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then //Checks if there is at least one application capable of receiving the intent.
    MainActivity.startActivity(printIntent) //Calls startActivity() to send the intent to the system.
  else
    ShowMessage('Receiver not found');

Based on the sample code from http://docwiki.embarcadero.com/CodeExamples/Seattle/en/FMX.Android_Intents_Sample 基于http://docwiki.embarcadero.com/CodeExamples/Seattle/en/FMX.Android_Intents_Sample的示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM