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
2020-03-19 19:33:23 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
166bf38d6065c24593b0a26805e53db647cbb813
166bf38d
1 parent
c159d98d
Fix iOS and Android behavior when an exception occures
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
15 deletions
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
printing/ios/Classes/PrintJob.swift
printing/ios/Classes/PrintingPlugin.swift
printing/lib/src/method_channel.dart
printing/macos/Classes/PrintJob.swift
printing/macos/Classes/PrintingPlugin.swift
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
View file @
166bf38
...
...
@@ -43,7 +43,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
case
"cancelJob"
:
{
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
printJob
.
cancelJob
();
printJob
.
cancelJob
(
null
);
result
.
success
(
1
);
break
;
}
...
...
@@ -125,18 +125,18 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
if
(
result
instanceof
byte
[])
{
printJob
.
setDocument
((
byte
[])
result
);
}
else
{
printJob
.
cancelJob
();
printJob
.
cancelJob
(
"Unknown data received"
);
}
}
@Override
public
void
error
(
String
errorCode
,
String
errorMessage
,
Object
errorDetails
)
{
printJob
.
cancelJob
();
printJob
.
cancelJob
(
errorMessage
);
}
@Override
public
void
notImplemented
()
{
printJob
.
cancelJob
();
printJob
.
cancelJob
(
"notImplemented"
);
}
});
}
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
View file @
166bf38
...
...
@@ -187,9 +187,10 @@ public class PrintingJob extends PrintDocumentAdapter {
printJob
=
printManager
.
print
(
name
,
this
,
null
);
}
void
cancelJob
()
{
void
cancelJob
(
String
message
)
{
if
(
callback
!=
null
)
callback
.
onLayoutCancelled
();
if
(
printJob
!=
null
)
printJob
.
cancel
();
printing
.
onCompleted
(
PrintingJob
.
this
,
false
,
message
);
}
static
void
sharePdf
(
final
Context
context
,
final
byte
[]
data
,
final
String
name
)
{
...
...
printing/ios/Classes/PrintJob.swift
View file @
166bf38
...
...
@@ -45,8 +45,9 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
}
}
func
cancelJob
()
{
func
cancelJob
(
_
error
:
String
?
)
{
pdfDocument
=
nil
printing
.
onCompleted
(
printJob
:
self
,
completed
:
false
,
error
:
error
as
NSString
?)
}
func
setDocument
(
_
data
:
Data
?)
{
...
...
printing/ios/Classes/PrintingPlugin.swift
View file @
166bf38
...
...
@@ -139,10 +139,15 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
channel
.
invokeMethod
(
"onLayout"
,
arguments
:
arg
,
result
:
{
(
result
:
Any
?)
->
Void
in
if
result
as?
Bool
==
false
{
printJob
.
cancelJob
()
}
else
{
printJob
.
cancelJob
(
nil
)
}
else
if
result
is
FlutterError
{
let
error
=
result
as!
FlutterError
printJob
.
cancelJob
(
error
.
message
)
}
else
if
result
is
FlutterStandardTypedData
{
let
object
=
result
as!
FlutterStandardTypedData
printJob
.
setDocument
(
object
.
data
)
}
else
{
printJob
.
cancelJob
(
"Unknown data type"
)
}
})
}
...
...
printing/lib/src/method_channel.dart
View file @
166bf38
...
...
@@ -44,7 +44,6 @@ class MethodChannelPrinting extends PrintingPlatform {
switch
(
call
.
method
)
{
case
'onLayout'
:
final
PrintJob
job
=
_printJobs
[
call
.
arguments
[
'job'
]];
try
{
final
PdfPageFormat
format
=
PdfPageFormat
(
call
.
arguments
[
'width'
],
call
.
arguments
[
'height'
],
...
...
@@ -61,9 +60,6 @@ class MethodChannelPrinting extends PrintingPlatform {
}
return
Uint8List
.
fromList
(
bytes
);
}
catch
(
e
)
{
return
e
.
toString
();
}
break
;
case
'onCompleted'
:
final
bool
completed
=
call
.
arguments
[
'completed'
];
...
...
printing/macos/Classes/PrintJob.swift
View file @
166bf38
...
...
@@ -101,7 +101,9 @@ public class PrintJob: NSView, NSSharingServicePickerDelegate {
)
}
public
func
cancelJob
()
{}
func
cancelJob
(
_
error
:
String
?)
{
printing
.
onCompleted
(
printJob
:
self
,
completed
:
false
,
error
:
error
as
NSString
?)
}
public
static
func
sharePdf
(
data
:
Data
,
withSourceRect
rect
:
CGRect
,
andName
name
:
String
)
{
let
tempFile
=
NSTemporaryDirectory
()
+
name
...
...
printing/macos/Classes/PrintingPlugin.swift
View file @
166bf38
...
...
@@ -139,10 +139,15 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
channel
.
invokeMethod
(
"onLayout"
,
arguments
:
arg
,
result
:
{
(
result
:
Any
?)
->
Void
in
if
result
as?
Bool
==
false
{
printJob
.
cancelJob
()
}
else
{
printJob
.
cancelJob
(
nil
)
}
else
if
result
is
FlutterError
{
let
error
=
result
as!
FlutterError
printJob
.
cancelJob
(
error
.
message
)
}
else
if
result
is
FlutterStandardTypedData
{
let
object
=
result
as!
FlutterStandardTypedData
printJob
.
setDocument
(
object
.
data
)
}
else
{
printJob
.
cancelJob
(
"Unknown data type"
)
}
})
}
...
...
Please
register
or
login
to post a comment