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
2019-09-18 20:46:29 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
35969dd6b84ae195dac95232da66f222a673f889
35969dd6
1 parent
e3c394ed
Cancel print job in case of layout error
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
2 deletions
printing/CHANGELOG.md
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
printing/ios/Classes/PageRenderer.swift
printing/ios/Classes/SwiftPrintingPlugin.swift
printing/lib/src/printing.dart
printing/CHANGELOG.md
View file @
35969dd
...
...
@@ -3,6 +3,7 @@
## 2.1.6
-
Add qrcode to example
-
Cancel print job in case of layout error
## 2.1.5
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
View file @
35969dd
...
...
@@ -149,7 +149,7 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa
}
}
catch
(
Exception
e
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"completed"
,
printJob
.
isCompleted
());
args
.
put
(
"completed"
,
printJob
!=
null
&&
printJob
.
isCompleted
());
args
.
put
(
"error"
,
e
.
getMessage
());
channel
.
invokeMethod
(
"onCompleted"
,
args
);
}
...
...
@@ -182,6 +182,11 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa
result
.
success
(
0
);
break
;
case
"cancelJob"
:
if
(
callback
!=
null
)
callback
.
onLayoutCancelled
();
if
(
printJob
!=
null
)
printJob
.
cancel
();
result
.
success
(
0
);
break
;
case
"sharePdf"
:
sharePdf
((
byte
[])
call
.
argument
(
"doc"
),
(
String
)
call
.
argument
(
"name"
));
result
.
success
(
0
);
...
...
printing/ios/Classes/PageRenderer.swift
View file @
35969dd
...
...
@@ -40,6 +40,11 @@ class PdfPrintPageRenderer: UIPrintPageRenderer {
ctx
?
.
drawPDFPage
(
page
!
)
}
func
cancelJob
()
{
pdfDocument
=
nil
lock
?
.
unlock
()
}
func
setDocument
(
_
data
:
Data
?)
{
let
bytesPointer
=
UnsafeMutablePointer
<
UInt8
>.
allocate
(
capacity
:
data
?
.
count
??
0
)
data
?
.
copyBytes
(
to
:
bytesPointer
,
count
:
data
?
.
count
??
0
)
...
...
printing/ios/Classes/SwiftPrintingPlugin.swift
View file @
35969dd
...
...
@@ -45,6 +45,11 @@ public class SwiftPrintingPlugin: NSObject, FlutterPlugin, UIPrintInteractionCon
writePdf
(
object
)
}
result
(
NSNumber
(
value
:
1
))
}
else
if
call
.
method
==
"cancelJob"
{
renderer
?
.
cancelJob
()
let
controller
=
UIPrintInteractionController
.
shared
controller
.
dismiss
(
animated
:
true
)
result
(
NSNumber
(
value
:
1
))
}
else
if
call
.
method
==
"sharePdf"
{
if
let
object
=
args
[
"doc"
]
as?
FlutterStandardTypedData
{
sharePdf
(
...
...
printing/lib/src/printing.dart
View file @
35969dd
...
...
@@ -28,6 +28,7 @@ mixin Printing {
static
Future
<
void
>
_handleMethod
(
MethodCall
call
)
async
{
switch
(
call
.
method
)
{
case
'onLayout'
:
try
{
final
List
<
int
>
bytes
=
await
_onLayout
(
PdfPageFormat
(
call
.
arguments
[
'width'
],
call
.
arguments
[
'height'
],
...
...
@@ -36,10 +37,19 @@ mixin Printing {
marginRight:
call
.
arguments
[
'marginRight'
],
marginBottom:
call
.
arguments
[
'marginBottom'
],
));
if
(
bytes
==
null
)
{
await
_channel
.
invokeMethod
<
void
>(
'cancelJob'
,
<
String
,
dynamic
>{});
break
;
}
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'doc'
:
Uint8List
.
fromList
(
bytes
),
};
return
await
_channel
.
invokeMethod
(
'writePdf'
,
params
);
await
_channel
.
invokeMethod
<
void
>(
'writePdf'
,
params
);
}
catch
(
e
)
{
print
(
'Unable to print:
$e
'
);
await
_channel
.
invokeMethod
<
void
>(
'cancelJob'
,
<
String
,
dynamic
>{});
}
break
;
case
'onCompleted'
:
final
bool
completed
=
call
.
arguments
[
'completed'
];
final
String
error
=
call
.
arguments
[
'error'
];
...
...
Please
register
or
login
to post a comment