Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter desktop #9

Closed
ghost opened this issue Sep 3, 2018 · 29 comments
Closed

Flutter desktop #9

ghost opened this issue Sep 3, 2018 · 29 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented Sep 3, 2018

This is a very ambitious issue.

There is no reason this can't work on desktop. The plugins can be replaced with windows and Mac equivalents and it should work.

@DavBfr
Copy link
Owner

DavBfr commented Sep 3, 2018

Are you talking about https://github.com/google/flutter-desktop-embedding ?
This thing is not ready for production yet.

@ghost
Copy link
Author

ghost commented Sep 3, 2018

Hey @DavBfr
Thats it..
I have gotten it workng on Mac and Windows. Its very nice to use. I was very surprised how fast and smooth it is.
The PDF code will work today.
The PDF plugin for Printing will need to be replaced. They do have plugins working today.

EDIT:
I presume your Flutter mobile sends the pdf out to the native PDF Reader and then the user gets to se it, presses print, and then it hooks into each system print spooler ?

@DavBfr DavBfr added the help wanted Extra attention is needed label Sep 10, 2018
@DavBfr DavBfr added the enhancement New feature or request label Sep 18, 2018
@DavBfr
Copy link
Owner

DavBfr commented Mar 24, 2019

@gedw99, any update on this issue?

@joeblew99
Copy link

hey @DavBfr Not yet !
Have been in a rush - wil get to this next week and integrate it with your package.

Just had an issue with IOS and printing :)

@DavBfr
Copy link
Owner

DavBfr commented Jul 23, 2019

Has this stalled?

@ReniDelonzek
Copy link

Hello, any news about this?

@DavBfr
Copy link
Owner

DavBfr commented Oct 7, 2019

Do we have a stable plugin api now for desktop-shells? I think MacOS and Linux should be easy to do using cups. But Windows will require a conversion from PDF to native print.

@ReniDelonzek
Copy link

Could you give me a light on how to do this? I need it to work at least on windows

@DavBfr
Copy link
Owner

DavBfr commented Oct 7, 2019

The most simple way to print a pdf on windows would be to generate the pdf, save it on a temporary folder and print using sumatrapdf as an external command line.

@ReniDelonzek
Copy link

Great, I'll study it better, thank you very much

@DavBfr
Copy link
Owner

DavBfr commented Oct 8, 2019

Here is a dart code using FFI to list the printers on a Windows machine.

import 'dart:convert';
import 'dart:ffi' as ffi;

typedef CEnumPrinters = ffi.Int32 Function(
  ffi.Int32 flags,
  ffi.Pointer<ffi.Uint8> name,
  ffi.Int32 level,
  ffi.Pointer<ffi.Uint8> printerEnum,
  ffi.Int32 buf,
  ffi.Pointer<ffi.Int32> needed,
  ffi.Pointer<ffi.Int32> returned,
);

typedef EnumPrinters = int Function(
  int flags,
  ffi.Pointer<ffi.Uint8> name,
  int level,
  ffi.Pointer<ffi.Uint8> printerEnum,
  int buf,
  ffi.Pointer<ffi.Int32> needed,
  ffi.Pointer<ffi.Int32> returned,
);

// Example of handling a simple C struct
class PrintInfo extends ffi.Struct<PrintInfo> {
  @ffi.Int32()
  int flags;

  @ffi.Uint64()
  int _description;

  @ffi.Uint64()
  int _name;

  @ffi.Uint64()
  int _comment;

  String _utf16ToString(int address) {
    final ptr = ffi.Pointer<ffi.Uint16>.fromAddress(address);
    final units = List<int>();
    var len = 0;
    while (true) {
      final char = ptr.elementAt(len++).load<int>();
      if (char == 0) break;
      units.add(char);
    }
    return Utf8Decoder().convert(units);
  }

  String get description => _utf16ToString(_description);

  String get name => _utf16ToString(_name);

  String get comment => _utf16ToString(_comment);

  @override
  String toString() =>
      '$runtimeType\n  Flags=$flags\n  Name=$name\n  Description=$description\n  Comment=$comment';
}

void main() {
  final dylib = ffi.DynamicLibrary.open('winspool.drv');
  final enumPrintersPointer =
      dylib.lookup<ffi.NativeFunction<CEnumPrinters>>('EnumPrintersW');
  final enumPrinters = enumPrintersPointer.asFunction<EnumPrinters>();

  final needed = ffi.Pointer<ffi.Int32>.allocate()..store(0);
  final returned = ffi.Pointer<ffi.Int32>.allocate()..store(0);
  enumPrinters(2, ffi.Pointer.fromAddress(0), 1, ffi.Pointer.fromAddress(0), 0,
      needed, returned);

  final bufferSize = needed.load<int>();
  final buffer = ffi.Pointer<ffi.Uint8>.allocate(count: bufferSize);
  final result = enumPrinters(
      2, ffi.Pointer.fromAddress(0), 1, buffer, bufferSize, needed, returned);

  if (result == 0) throw ('Error listing the printers');

  final count = returned.load<int>();

  final a = ffi.Pointer<PrintInfo>.fromAddress(buffer.address);
  for (int i = 0; i < count; i++) {
    print(a.elementAt(i).load<PrintInfo>());
  }

  buffer.free();
}

@DavBfr
Copy link
Owner

DavBfr commented Dec 12, 2019

macOS desktop support is fully implemented in printing 3.0.0

@DavBfr
Copy link
Owner

DavBfr commented Dec 23, 2019

https://docs.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes#displaying-the-print-dialog-box

@viveknimkarde
Copy link
Contributor

It's been long time with no activity on this issue. Anyone working on getting windows support for printing ?

please share the progress so that we can make this plugin cross-platform.

@DavBfr
Copy link
Owner

DavBfr commented Oct 26, 2020

Here is a branch with a windows plugin, if some C++ / windows experts want to help.

https://github.com/DavBfr/dart_pdf/tree/windows

The goal is to use Pdfium for the rendering and share as much code as possible with the Linux implementation, which is not the case yet.

@viveknimkarde
Copy link
Contributor

viveknimkarde commented Oct 26, 2020

Thanks for the update @DavBfr .

I will try to work on C++ part, although I am not a windows expert.

This plugin is very essential to make cross-platform apps.

@viveknimkarde
Copy link
Contributor

@DavBfr did you take a look at https://pub.dev/packages/windows_printing

Any learnings from this plugin implementation.

@DavBfr
Copy link
Owner

DavBfr commented Oct 26, 2020

@viveknimkarde yes I saw it, but it's really limited.

@DavBfr
Copy link
Owner

DavBfr commented Oct 28, 2020

We're almost there!

windows-print

@viveknimkarde
Copy link
Contributor

That's just great @DavBfr. I will test few use cases and we can get in out in next release.

@DavBfr
Copy link
Owner

DavBfr commented Oct 29, 2020

Here you are: printing version 3.7.0 has Windows Desktop support, for x64 builds.

It's beta quality for now, full of memory leaks and missing bits, but the feature is there.

@rizirf-connect
Copy link

Hey @DavBfr thanks for your work. My problem is that I am using thermal printer for print billing receipt but it always print blank receipts. Any help would be appreciated..

@rizirf-connect
Copy link

I am printing simple hello world but it does not print anything.
``final font = await rootBundle.load("fonts/Helvetica.ttf");
final ttf = pw.Font.ttf(font);

    final doc = pw.Document();

    doc.addPage(
      pw.Page(
        pageFormat: PdfPageFormat.letter,
        build: (pw.Context context) {
          return pw.Text(
            "Hello World",
            style : pw.TextStyle(font: ttf, fontSize: 40)
          );
        },
      ),
    );

    final output = await getTemporaryDirectory();
    final file = File("${output.path}/example.pdf");
    await file.writeAsBytes(doc.save());

    await Printing.layoutPdf(
      onLayout: (PdfPageFormat format) async => doc.save(),
    );

@DavBfr
Copy link
Owner

DavBfr commented Oct 31, 2020

@rizirf-connect

Look at the windows CPP code. And adapt to your situation. I don't have a thermal printer.

@rizirf-connect
Copy link

Sir I dont understand anything can you guide me plzz how to solve this problem.

@rizirf-connect
Copy link

Hey @DavBfr can you please tell me what kind of problem i am facing right now..??

@DavBfr
Copy link
Owner

DavBfr commented Nov 1, 2020

@rizirf-connect I don't know. Please share more code.

@rizirf-connect
Copy link

rizirf-connect commented Nov 2, 2020

@DavBfr sir I am using all this code to simply print hello world in my thermal printer, but It is printing blank paper.

@DavBfr
Copy link
Owner

DavBfr commented Nov 20, 2020

Closing this issue as #468 is the last OS to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants