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-02-20 09:57:06 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
01f28f24fbb0d51fb9f0b96d614bb67f9d37ece1
01f28f24
1 parent
a24aeccd
Improve Linux and Windows printing
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
29 deletions
printing/lib/src/pdf_preview.dart
printing/linux/print_job.cc
printing/windows/print_job.cpp
printing/windows/printing.cpp
printing/lib/src/pdf_preview.dart
View file @
01f28f2
...
...
@@ -27,6 +27,7 @@ class PdfPreview extends StatefulWidget {
this
.
pageFormats
,
this
.
onError
,
this
.
onPrinted
,
this
.
onPrintError
,
this
.
onShared
,
this
.
scrollViewDecoration
,
this
.
pdfPreviewPageDecoration
,
...
...
@@ -65,12 +66,15 @@ class PdfPreview extends StatefulWidget {
/// List of page formats the user can choose
final
Map
<
String
,
PdfPageFormat
>?
pageFormats
;
///
Called if an error creating the Pdf occur
ed
///
Widget to display if the PDF document cannot be display
ed
final
Widget
Function
(
BuildContext
context
)?
onError
;
/// Called if the user prints the pdf document
final
void
Function
(
BuildContext
context
)?
onPrinted
;
/// Called if an error creating the Pdf occured
final
void
Function
(
BuildContext
context
,
dynamic
error
)?
onPrintError
;
/// Called if the user shares the pdf document
final
void
Function
(
BuildContext
context
)?
onShared
;
...
...
@@ -514,8 +518,8 @@ class _PdfPreviewState extends State<PdfPreview> {
widget
.
onPrinted
!(
context
);
}
}
catch
(
e
)
{
if
(
widget
.
onError
!=
null
)
{
widget
.
onError
!(
context
);
if
(
widget
.
onPrintError
!=
null
)
{
widget
.
onPrintError
!(
context
,
e
);
}
}
}
...
...
printing/linux/print_job.cc
View file @
01f28f2
...
...
@@ -138,29 +138,34 @@ bool print_job::print_pdf(const gchar* name,
GTK_PRINT_UNIX_DIALOG
(
gtk_print_unix_dialog_new
(
name
,
nullptr
));
gtk_print_unix_dialog_set_manual_capabilities
(
dialog
,
(
GtkPrintCapabilities
)(
GTK_PRINT_CAPABILITY_GENERATE_PDF
));
gtk_print_unix_dialog_set_embed_page_setup
(
dialog
,
true
);
gtk_print_unix_dialog_set_support_selection
(
dialog
,
false
);
gtk_widget_realize
(
GTK_WIDGET
(
dialog
));
auto
response
=
gtk_dialog_run
(
GTK_DIALOG
(
dialog
));
gtk_widget_hide
(
GTK_WIDGET
(
dialog
));
switch
(
response
)
{
case
GTK_RESPONSE_OK
:
{
_printer
=
gtk_print_unix_dialog_get_selected_printer
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
settings
=
gtk_print_unix_dialog_get_settings
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
setup
=
gtk_print_unix_dialog_get_page_setup
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
gtk_widget_destroy
(
GTK_WIDGET
(
dialog
));
}
break
;
case
GTK_RESPONSE_DELETE_EVENT
:
// Fall through.
case
GTK_RESPONSE_CANCEL
:
// Cancel
case
GTK_RESPONSE_APPLY
:
// Preview
default:
gtk_widget_destroy
(
GTK_WIDGET
(
dialog
));
on_completed
(
this
,
false
,
nullptr
);
return
true
;
auto
loop
=
true
;
while
(
loop
)
{
auto
response
=
gtk_dialog_run
(
GTK_DIALOG
(
dialog
));
switch
(
response
)
{
case
GTK_RESPONSE_OK
:
{
_printer
=
gtk_print_unix_dialog_get_selected_printer
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
settings
=
gtk_print_unix_dialog_get_settings
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
setup
=
gtk_print_unix_dialog_get_page_setup
(
GTK_PRINT_UNIX_DIALOG
(
dialog
));
gtk_widget_destroy
(
GTK_WIDGET
(
dialog
));
loop
=
false
;
}
break
;
case
GTK_RESPONSE_APPLY
:
// Preview
break
;
default
:
// Cancel
gtk_widget_destroy
(
GTK_WIDGET
(
dialog
));
on_completed
(
this
,
false
,
nullptr
);
return
true
;
}
}
}
...
...
@@ -172,8 +177,8 @@ bool print_job::print_pdf(const gchar* name,
return
false
;
}
auto
_width
=
gtk_page_setup_get_page_width
(
setup
,
GTK_UNIT_POINTS
);
auto
_height
=
gtk_page_setup_get_page_height
(
setup
,
GTK_UNIT_POINTS
);
auto
_width
=
gtk_page_setup_get_paper_width
(
setup
,
GTK_UNIT_POINTS
);
auto
_height
=
gtk_page_setup_get_paper_height
(
setup
,
GTK_UNIT_POINTS
);
auto
_marginLeft
=
gtk_page_setup_get_left_margin
(
setup
,
GTK_UNIT_POINTS
);
auto
_marginTop
=
gtk_page_setup_get_top_margin
(
setup
,
GTK_UNIT_POINTS
);
auto
_marginRight
=
gtk_page_setup_get_right_margin
(
setup
,
GTK_UNIT_POINTS
);
...
...
printing/windows/print_job.cpp
View file @
01f28f2
...
...
@@ -71,7 +71,7 @@ std::wstring fromUtf8(std::string str) {
}
PrintJob
::
PrintJob
(
Printing
*
printing
,
int
index
)
:
printing
(
printing
),
index
(
index
)
{}
:
printing
{
printing
},
index
{
index
}
{}
bool
PrintJob
::
printPdf
(
std
::
string
name
,
std
::
string
printer
)
{
documentName
=
name
;
...
...
@@ -102,11 +102,18 @@ bool PrintJob::printPdf(std::string name, std::string printer) {
auto
r
=
PrintDlg
(
&
pd
);
if
(
r
==
1
)
{
if
(
r
!=
1
)
{
printing
->
onCompleted
(
this
,
false
,
""
);
DeleteDC
(
hDC
);
GlobalFree
(
hDevNames
);
ClosePrinter
(
hDevMode
);
return
true
;
}
hDC
=
pd
.
hDC
;
hDevMode
=
pd
.
hDevMode
;
hDevNames
=
pd
.
hDevNames
;
}
}
else
{
hDC
=
CreateDC
(
TEXT
(
"WINSPOOL"
),
fromUtf8
(
printer
).
c_str
(),
NULL
,
NULL
);
if
(
!
hDC
)
{
...
...
@@ -235,6 +242,8 @@ void PrintJob::writeJob(std::vector<uint8_t> data) {
DeleteDC
(
hDC
);
GlobalFree
(
hDevNames
);
ClosePrinter
(
hDevMode
);
printing
->
onCompleted
(
this
,
true
,
""
);
}
void
PrintJob
::
cancelJob
(
std
::
string
error
)
{}
...
...
printing/windows/printing.cpp
View file @
01f28f2
...
...
@@ -55,7 +55,7 @@ void Printing::onPageRasterEnd(PrintJob* job) {
class
OnLayoutResult
:
public
flutter
::
MethodResult
<
flutter
::
EncodableValue
>
{
public
:
OnLayoutResult
(
PrintJob
*
job
)
:
job
(
job
)
{}
OnLayoutResult
(
PrintJob
*
job
)
:
job
{
job
}
{}
private
:
PrintJob
*
job
;
...
...
Please
register
or
login
to post a comment