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
Alban Lecuivre
2022-01-12 09:28:40 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
47fddf11aa8ec1ff751b710ab71723b4190e3322
47fddf11
1 parent
2557e517
feat: enable usage of printer's settings
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
15 deletions
printing/lib/src/interface.dart
printing/lib/src/method_channel.dart
printing/lib/src/printing.dart
printing/windows/print_job.cpp
printing/windows/print_job.h
printing/windows/printing_plugin.cpp
printing/lib/src/interface.dart
View file @
47fddf1
...
...
@@ -65,6 +65,7 @@ abstract class PrintingPlatform extends PlatformInterface {
String
name
,
PdfPageFormat
format
,
bool
dynamicLayout
,
bool
usePrinterSettings
,
);
/// Enumerate the available printers on the system.
...
...
printing/lib/src/method_channel.dart
View file @
47fddf1
...
...
@@ -171,6 +171,7 @@ class MethodChannelPrinting extends PrintingPlatform {
String
name
,
PdfPageFormat
format
,
bool
dynamicLayout
,
bool
usePrinterSettings
,
)
async
{
final
job
=
_printJobs
.
add
(
onCompleted:
Completer
<
bool
>(),
...
...
@@ -188,6 +189,7 @@ class MethodChannelPrinting extends PrintingPlatform {
'marginRight'
:
format
.
marginRight
,
'marginBottom'
:
format
.
marginBottom
,
'dynamic'
:
dynamicLayout
,
'usePrinterSettings'
:
usePrinterSettings
,
};
await
_channel
.
invokeMethod
<
int
>(
'printPdf'
,
params
);
...
...
printing/lib/src/printing.dart
View file @
47fddf1
...
...
@@ -35,11 +35,16 @@ mixin Printing {
/// returns a future with a `bool` set to true if the document is printed
/// and false if it is canceled.
/// throws an exception in case of error
///
/// Set [usePrinterSettings] to true to use the configuration defined by
/// the printer. May not work for all the printers and can depend on the
/// drivers. (Supported platforms: Windows)
static
Future
<
bool
>
layoutPdf
({
required
LayoutCallback
onLayout
,
String
name
=
'Document'
,
PdfPageFormat
format
=
PdfPageFormat
.
standard
,
bool
dynamicLayout
=
true
,
bool
usePrinterSettings
=
false
,
})
{
return
PrintingPlatform
.
instance
.
layoutPdf
(
null
,
...
...
@@ -47,6 +52,7 @@ mixin Printing {
name
,
format
,
dynamicLayout
,
usePrinterSettings
,
);
}
...
...
@@ -118,12 +124,17 @@ mixin Printing {
///
/// This is not supported on all platforms. Check the result of [info] to
/// find at runtime if this feature is available or not.
///
/// Set [usePrinterSettings] to true to use the configuration defined by
/// the printer. May not work for all the printers and can depend on the
/// drivers. (Supported platforms: Windows)
static
FutureOr
<
bool
>
directPrintPdf
({
required
Printer
printer
,
required
LayoutCallback
onLayout
,
String
name
=
'Document'
,
PdfPageFormat
format
=
PdfPageFormat
.
standard
,
bool
dynamicLayout
=
true
,
bool
usePrinterSettings
=
false
,
})
{
return
PrintingPlatform
.
instance
.
layoutPdf
(
printer
,
...
...
@@ -131,6 +142,7 @@ mixin Printing {
name
,
format
,
dynamicLayout
,
usePrinterSettings
,
);
}
...
...
printing/windows/print_job.cpp
View file @
47fddf1
...
...
@@ -76,23 +76,30 @@ PrintJob::PrintJob(Printing* printing, int index)
bool
PrintJob
::
printPdf
(
std
::
string
name
,
std
::
string
printer
,
double
width
,
double
height
)
{
double
height
,
bool
usePrinterSettings
)
{
documentName
=
name
;
auto
dm
=
static_cast
<
DEVMODE
*>
(
GlobalAlloc
(
0
,
sizeof
(
DEVMODE
)));
ZeroMemory
(
dm
,
sizeof
(
DEVMODE
));
dm
->
dmSize
=
sizeof
(
DEVMODE
);
dm
->
dmFields
=
DM_ORIENTATION
|
DM_PAPERSIZE
|
DM_PAPERLENGTH
|
DM_PAPERWIDTH
;
dm
->
dmPaperSize
=
0
;
if
(
width
>
height
)
{
dm
->
dmOrientation
=
DMORIENT_LANDSCAPE
;
dm
->
dmPaperWidth
=
static_cast
<
short
>
(
round
(
height
*
254
/
72
));
dm
->
dmPaperLength
=
static_cast
<
short
>
(
round
(
width
*
254
/
72
));
auto
dm
;
if
(
usePrinterSettings
){
dm
=
NULL
;
// to use default driver config
}
else
{
dm
->
dmOrientation
=
DMORIENT_PORTRAIT
;
dm
->
dmPaperWidth
=
static_cast
<
short
>
(
round
(
width
*
254
/
72
));
dm
->
dmPaperLength
=
static_cast
<
short
>
(
round
(
height
*
254
/
72
));
dm
=
static_cast
<
DEVMODE
*>
(
GlobalAlloc
(
0
,
sizeof
(
DEVMODE
)));
ZeroMemory
(
dm
,
sizeof
(
DEVMODE
));
dm
->
dmSize
=
sizeof
(
DEVMODE
);
dm
->
dmFields
=
DM_ORIENTATION
|
DM_PAPERSIZE
|
DM_PAPERLENGTH
|
DM_PAPERWIDTH
;
dm
->
dmPaperSize
=
0
;
if
(
width
>
height
)
{
dm
->
dmOrientation
=
DMORIENT_LANDSCAPE
;
dm
->
dmPaperWidth
=
static_cast
<
short
>
(
round
(
height
*
254
/
72
));
dm
->
dmPaperLength
=
static_cast
<
short
>
(
round
(
width
*
254
/
72
));
}
else
{
dm
->
dmOrientation
=
DMORIENT_PORTRAIT
;
dm
->
dmPaperWidth
=
static_cast
<
short
>
(
round
(
width
*
254
/
72
));
dm
->
dmPaperLength
=
static_cast
<
short
>
(
round
(
height
*
254
/
72
));
}
}
if
(
printer
.
empty
())
{
PRINTDLG
pd
;
...
...
printing/windows/print_job.h
View file @
47fddf1
...
...
@@ -74,7 +74,8 @@ class PrintJob {
bool
printPdf
(
std
::
string
name
,
std
::
string
printer
,
double
width
,
double
height
);
double
height
,
bool
usePrinterSettings
);
void
writeJob
(
std
::
vector
<
uint8_t
>
data
);
...
...
printing/windows/printing_plugin.cpp
View file @
47fddf1
...
...
@@ -78,10 +78,12 @@ class PrintingPlugin : public flutter::Plugin {
arguments
->
find
(
flutter
::
EncodableValue
(
"width"
))
->
second
);
auto
height
=
std
::
get
<
double
>
(
arguments
->
find
(
flutter
::
EncodableValue
(
"height"
))
->
second
);
auto
usePrinterSettings
=
std
::
get
<
bool
>
(
arguments
->
find
(
flutter
::
EncodableValue
(
"usePrinterSettings"
))
->
second
);
auto
vJob
=
arguments
->
find
(
flutter
::
EncodableValue
(
"job"
));
auto
jobNum
=
vJob
!=
arguments
->
end
()
?
std
::
get
<
int
>
(
vJob
->
second
)
:
-
1
;
auto
job
=
new
PrintJob
{
&
printing
,
jobNum
};
auto
res
=
job
->
printPdf
(
name
,
printer
,
width
,
height
);
auto
res
=
job
->
printPdf
(
name
,
printer
,
width
,
height
,
usePrinterSettings
);
if
(
!
res
)
{
delete
job
;
}
...
...
Please
register
or
login
to post a comment