Comments (29)
from dart_pdf.
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.
macOS desktop support is fully implemented in printing 3.0.0
from dart_pdf.
We're almost there!
from dart_pdf.
That's just great @DavBfr. I will test few use cases and we can get in out in next release.
from dart_pdf.
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.
@viveknimkarde yes I saw it, but it's really limited.
from dart_pdf.
Are you talking about https://github.com/google/flutter-desktop-embedding ?
This thing is not ready for production yet.
from dart_pdf.
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.
@gedw99, any update on this issue?
from dart_pdf.
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.
Has this stalled?
from dart_pdf.
Hello, any news about this?
from dart_pdf.
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.
Could you give me a light on how to do this? I need it to work at least on windows
from dart_pdf.
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.
Great, I'll study it better, thank you very much
from dart_pdf.
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.
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.
@DavBfr did you take a look at https://pub.dev/packages/windows_printing
Any learnings from this plugin implementation.
from dart_pdf.
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.
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.
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.
Look at the windows CPP code. And adapt to your situation. I don't have a thermal printer.
from dart_pdf.
Sir I dont understand anything can you guide me plzz how to solve this problem.
from dart_pdf.
Hey @DavBfr can you please tell me what kind of problem i am facing right now..??
from dart_pdf.
@rizirf-connect I don't know. Please share more code.
from dart_pdf.
@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.
Closing this issue as #468 is the last OS to support.
from dart_pdf.
Related Issues (20)
- Error on mac os build with flutter 3.21.0-1.0.pre.2 HOT 1
- Paragraph inside Partition does not pass content to the next page as expected.
- Printing a PDF with layoutPdf fails to print: The 'net.nfet.printing' channel sent a message from native to Flutter on a non-platform thread
- Bangla text Rendering issue.
- PdfPreview renders inaccurate colors on Android
- Khmer Language is still does't working, Please help to improve too
- I/flutter ( 3281): Exception: Exception: Unable to guess the image type 1311710 bytes
- Does not apply PdfColor in alpha HOT 1
- Pdf/A
- Restrictions on customizations
- The Urdu tag is for issues relating to displaying user interfaces and managing data in Udru written language
- When I press the shared button it calls onPrinted instead of onShared
- Extend NewPage with freeSpace HOT 3
- Callback for Print Success/Failure Notification HOT 3
- Not forwarding email extras when sharing
- Emoji's not displaying in PDF generated with dart_pdf HOT 2
- Send PDF to a wifi printer by ip
- Merging two pdf
- Merge two PDF's HOT 4
- Updating PDF page
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart_pdf.