Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2021-01-02 12:19:22 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
86a040a8de869c6ca9a8eedc58338a04886fa0ea
86a040a8
1 parent
e1af3ddc
Improve Windows directPrint
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
85 additions
and
19 deletions
printing/CHANGELOG.md
printing/lib/src/method_channel.dart
printing/lib/src/printer.dart
printing/lib/src/printing.dart
printing/windows/CMakeLists.txt
printing/windows/print_job.cpp
printing/windows/print_job.h
printing/windows/printing_plugin.cpp
printing/CHANGELOG.md
View file @
86a040a
...
...
@@ -6,6 +6,7 @@
-
Document.save() now returns a Future
-
Implement pan and zoom on PdfPreview widget
-
Improve orientation handling
-
Improve directPrint
## 3.7.2
...
...
printing/lib/src/method_channel.dart
View file @
86a040a
...
...
@@ -165,6 +165,9 @@ class MethodChannelPrinting extends PrintingPlatform {
name:
printer
[
'name'
],
model:
printer
[
'model'
],
location:
printer
[
'location'
],
comment:
printer
[
'comment'
],
isDefault:
printer
[
'default'
],
available:
printer
[
'available'
],
));
}
...
...
printing/lib/src/printer.dart
View file @
86a040a
...
...
@@ -25,6 +25,9 @@ class Printer {
this
.
name
,
this
.
model
,
this
.
location
,
this
.
comment
,
this
.
isDefault
=
false
,
this
.
available
=
true
,
})
:
assert
(
url
!=
null
);
/// The platform specific printer identification
...
...
@@ -39,6 +42,15 @@ class Printer {
/// The physical location of the printer
final
String
location
;
/// A user comment about the printer
final
String
comment
;
/// Is this the default printer on the system
final
bool
isDefault
;
/// The printer is available for printing
final
bool
available
;
@override
String
toString
()
=>
name
??
url
;
}
...
...
printing/lib/src/printing.dart
View file @
86a040a
...
...
@@ -65,6 +65,7 @@ mixin Printing {
static
Future
<
Printer
>
pickPrinter
({
@required
BuildContext
context
,
Rect
bounds
,
String
title
,
})
async
{
final
_info
=
await
info
();
...
...
@@ -74,17 +75,35 @@ mixin Printing {
'Pass a BuildContext to pickPrinter to display a selection list'
,
);
final
printers
=
await
listPrinters
();
printers
.
sort
((
a
,
b
)
{
if
(
a
.
isDefault
)
{
return
-
1
;
}
if
(
b
.
isDefault
)
{
return
1
;
}
return
a
.
name
.
compareTo
(
b
.
name
);
});
return
await
showDialog
<
Printer
>(
context:
context
,
builder:
(
context
)
=>
SimpleDialog
(
children:
printers
.
map
<
Widget
>(
(
e
)
=>
SimpleDialogOption
(
child:
Text
(
e
.
name
),
onPressed:
()
=>
Navigator
.
of
(
context
).
pop
(
e
),
title:
Text
(
title
??
'Select Printer'
),
children:
[
for
(
final
printer
in
printers
)
if
(
printer
.
available
)
SimpleDialogOption
(
child:
Text
(
printer
.
name
,
style:
TextStyle
(
fontStyle:
printer
.
isDefault
?
FontStyle
.
italic
:
FontStyle
.
normal
,
),
),
onPressed:
()
=>
Navigator
.
of
(
context
).
pop
(
printer
),
),
)
.
toList
(),
],
),
);
}
...
...
printing/windows/CMakeLists.txt
100755 → 100644
View file @
86a040a
printing/windows/print_job.cpp
View file @
86a040a
...
...
@@ -134,6 +134,7 @@ bool PrintJob::printPdf(std::string name) {
ZeroMemory
(
dm
,
sizeof
(
DEVMODE
));
dm
->
dmFields
=
DM_ORIENTATION
;
dm
->
dmOrientation
=
2
;
printf
(
"Printing ...
\n
"
);
// Initialize PRINTDLG
ZeroMemory
(
&
pd
,
sizeof
(
pd
));
...
...
@@ -186,19 +187,28 @@ bool PrintJob::printPdf(std::string name) {
}
std
::
vector
<
Printer
>
PrintJob
::
listPrinters
()
{
LPTSTR
defaultPrinter
;
DWORD
size
=
0
;
GetDefaultPrinter
(
nullptr
,
&
size
);
defaultPrinter
=
static_cast
<
LPTSTR
>
(
malloc
(
size
*
sizeof
(
TCHAR
)));
if
(
!
GetDefaultPrinter
(
defaultPrinter
,
&
size
))
{
size
=
0
;
}
auto
printers
=
std
::
vector
<
Printer
>
{};
DWORD
needed
=
0
;
DWORD
returned
=
0
;
const
auto
flags
=
PRINTER_ENUM_LOCAL
|
PRINTER_ENUM_CONNECTIONS
;
EnumPrinters
(
flags
,
nullptr
,
1
,
nullptr
,
0
,
&
needed
,
&
returned
);
EnumPrinters
(
flags
,
nullptr
,
2
,
nullptr
,
0
,
&
needed
,
&
returned
);
auto
buffer
=
(
PRINTER_INFO_
1
*
)
malloc
(
needed
);
auto
buffer
=
(
PRINTER_INFO_
2
*
)
malloc
(
needed
);
if
(
!
buffer
)
{
return
printers
;
}
auto
result
=
EnumPrinters
(
flags
,
nullptr
,
1
,
(
LPBYTE
)
buffer
,
needed
,
&
needed
,
auto
result
=
EnumPrinters
(
flags
,
nullptr
,
2
,
(
LPBYTE
)
buffer
,
needed
,
&
needed
,
&
returned
);
if
(
result
==
0
)
{
...
...
@@ -208,14 +218,17 @@ std::vector<Printer> PrintJob::listPrinters() {
for
(
DWORD
i
=
0
;
i
<
returned
;
i
++
)
{
printers
.
push_back
(
Printer
{
toUtf8
(
buffer
[
i
].
pName
),
toUtf8
(
buffer
[
i
].
pName
),
toUtf8
(
buffer
[
i
].
pDescription
),
toUtf8
(
buffer
[
i
].
pPrinterName
),
toUtf8
(
buffer
[
i
].
pPrinterName
),
toUtf8
(
buffer
[
i
].
pDriverName
),
toUtf8
(
buffer
[
i
].
pLocation
),
toUtf8
(
buffer
[
i
].
pComment
),
});
size
>
0
&&
_tcsncmp
(
buffer
[
i
].
pPrinterName
,
defaultPrinter
,
size
)
==
0
,
(
buffer
[
i
].
Status
&
(
PRINTER_STATUS_NOT_AVAILABLE
|
PRINTER_STATUS_ERROR
|
PRINTER_STATUS_OFFLINE
|
PRINTER_STATUS_PAUSED
))
==
0
});
}
free
(
buffer
);
free
(
defaultPrinter
);
return
printers
;
}
...
...
printing/windows/print_job.h
View file @
86a040a
...
...
@@ -34,13 +34,25 @@ struct Printer {
const
std
::
string
name
;
const
std
::
string
url
;
const
std
::
string
model
;
const
std
::
string
description
;
const
std
::
string
location
;
const
std
::
string
comment
;
const
bool
default
;
const
bool
available
;
Printer
(
std
::
string
name
,
std
::
string
url
,
std
::
string
model
,
std
::
string
description
)
:
name
(
name
),
url
(
url
),
model
(
model
),
description
(
description
)
{}
std
::
string
location
,
std
::
string
comment
,
bool
default
,
bool
available
)
:
name
(
name
),
url
(
url
),
model
(
model
),
location
(
location
),
comment
(
comment
),
default
(
default
),
available
(
available
)
{}
};
class
PrintJob
{
...
...
printing/windows/printing_plugin.cpp
View file @
86a040a
...
...
@@ -125,8 +125,14 @@ class PrintingPlugin : public flutter::Plugin {
flutter
::
EncodableValue
(
printer
.
url
);
mp
[
flutter
::
EncodableValue
(
"model"
)]
=
flutter
::
EncodableValue
(
printer
.
model
);
mp
[
flutter
::
EncodableValue
(
"description"
)]
=
flutter
::
EncodableValue
(
printer
.
description
);
mp
[
flutter
::
EncodableValue
(
"location"
)]
=
flutter
::
EncodableValue
(
printer
.
location
);
mp
[
flutter
::
EncodableValue
(
"comment"
)]
=
flutter
::
EncodableValue
(
printer
.
comment
);
mp
[
flutter
::
EncodableValue
(
"default"
)]
=
flutter
::
EncodableValue
(
printer
.
default
);
mp
[
flutter
::
EncodableValue
(
"available"
)]
=
flutter
::
EncodableValue
(
printer
.
available
);
pl
.
push_back
(
mp
);
}
result
->
Success
(
pl
);
...
...
Please
register
or
login
to post a comment