Git Product home page Git Product logo

Comments (29)

DavBfr avatar DavBfr commented on May 20, 2024 5

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024 3

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();
}

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024 3

macOS desktop support is fully implemented in printing 3.0.0

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024 3

We're almost there!

windows-print

from dart_pdf.

viveknimkarde avatar viveknimkarde commented on May 20, 2024 2

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

from dart_pdf.

viveknimkarde avatar viveknimkarde commented on May 20, 2024 1

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.

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024 1

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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

from dart_pdf.

 avatar commented on May 20, 2024

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 ?

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

@gedw99, any update on this issue?

from dart_pdf.

joeblew99 avatar joeblew99 commented on May 20, 2024

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 :)

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

Has this stalled?

from dart_pdf.

ReniDelonzek avatar ReniDelonzek commented on May 20, 2024

Hello, any news about this?

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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.

from dart_pdf.

ReniDelonzek avatar ReniDelonzek commented on May 20, 2024

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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.

from dart_pdf.

ReniDelonzek avatar ReniDelonzek commented on May 20, 2024

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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.

from dart_pdf.

viveknimkarde avatar viveknimkarde commented on May 20, 2024

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.

from dart_pdf.

viveknimkarde avatar viveknimkarde commented on May 20, 2024

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

Any learnings from this plugin implementation.

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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.

from dart_pdf.

rizirf-connect avatar rizirf-connect commented on May 20, 2024

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..

from dart_pdf.

rizirf-connect avatar rizirf-connect commented on May 20, 2024

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(),
    );

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

@rizirf-connect

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

from dart_pdf.

rizirf-connect avatar rizirf-connect commented on May 20, 2024

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

from dart_pdf.

rizirf-connect avatar rizirf-connect commented on May 20, 2024

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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

from dart_pdf.

rizirf-connect avatar rizirf-connect commented on May 20, 2024

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

from dart_pdf.

DavBfr avatar DavBfr commented on May 20, 2024

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

from dart_pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.