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-04-09 09:10:07 -0300
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
bbe5dff9e2c3b467b05cb7b7891775a60edaa49c
bbe5dff9
2 parents
6f87929b
ce7ec887
Merge branch 'deepak786-share_adjustments'
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
83 additions
and
10 deletions
printing/CHANGELOG.md
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/printing_web.dart
printing/lib/src/interface.dart
printing/lib/src/method_channel.dart
printing/lib/src/pdf_preview.dart
printing/lib/src/printing.dart
printing/pubspec.yaml
printing/test/printing_test.dart
printing/CHANGELOG.md
View file @
bbe5dff
# Changelog
## 5.
0.5
## 5.
1.0
-
Fix PdfPreview timer dispose
[
wwl901215
]
-
Remove unnecessary _raster call in PdfPreview
[
yaymalaga
]
-
Added subject, body and email parameters in sharePdf
[
Deepak
]
-
Subject, body and emails parameter to pdf preview
[
Deepak
]
## 5.0.4
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
View file @
bbe5dff
...
...
@@ -49,7 +49,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
case
"sharePdf"
:
{
final
byte
[]
document
=
call
.
argument
(
"doc"
);
final
String
name
=
call
.
argument
(
"name"
);
PrintingJob
.
sharePdf
(
activity
,
document
,
name
);
final
String
subject
=
call
.
argument
(
"subject"
);
final
String
body
=
call
.
argument
(
"body"
);
final
ArrayList
<
String
>
emails
=
call
.
argument
(
"emails"
);
PrintingJob
.
sharePdf
(
activity
,
document
,
name
,
subject
,
body
,
emails
);
result
.
success
(
1
);
break
;
}
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
View file @
bbe5dff
...
...
@@ -207,7 +207,8 @@ public class PrintingJob extends PrintDocumentAdapter {
printing
.
onCompleted
(
PrintingJob
.
this
,
false
,
message
);
}
static
void
sharePdf
(
final
Context
context
,
final
byte
[]
data
,
final
String
name
)
{
static
void
sharePdf
(
final
Context
context
,
final
byte
[]
data
,
final
String
name
,
final
String
subject
,
final
String
body
,
final
ArrayList
<
String
>
emails
)
{
assert
name
!=
null
;
try
{
...
...
@@ -233,6 +234,10 @@ public class PrintingJob extends PrintDocumentAdapter {
shareIntent
.
setType
(
"application/pdf"
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_STREAM
,
apkURI
);
shareIntent
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_SUBJECT
,
subject
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_TEXT
,
body
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_EMAIL
,
emails
!=
null
?
emails
.
toArray
(
new
String
[
0
])
:
null
);
Intent
chooserIntent
=
Intent
.
createChooser
(
shareIntent
,
null
);
List
<
ResolveInfo
>
resInfoList
=
context
.
getPackageManager
().
queryIntentActivities
(
chooserIntent
,
PackageManager
.
MATCH_DEFAULT_ONLY
);
...
...
printing/ios/Classes/PrintJob.swift
View file @
bbe5dff
...
...
@@ -186,7 +186,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
)
}
static
func
sharePdf
(
data
:
Data
,
withSourceRect
rect
:
CGRect
,
andName
name
:
String
)
{
static
func
sharePdf
(
data
:
Data
,
withSourceRect
rect
:
CGRect
,
andName
name
:
String
,
subject
:
String
?,
body
:
String
?
)
{
let
tmpDirURL
=
URL
(
fileURLWithPath
:
NSTemporaryDirectory
(),
isDirectory
:
true
)
let
fileURL
=
tmpDirURL
.
appendingPathComponent
(
name
)
...
...
@@ -197,7 +197,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
return
}
let
activityViewController
=
UIActivityViewController
(
activityItems
:
[
fileURL
],
applicationActivities
:
nil
)
let
activityViewController
=
UIActivityViewController
(
activityItems
:
[
fileURL
,
body
],
applicationActivities
:
nil
)
activityViewController
.
setValue
(
subject
,
forKey
:
"subject"
)
if
UI_USER_INTERFACE_IDIOM
()
==
.
pad
{
let
controller
:
UIViewController
?
=
UIApplication
.
shared
.
keyWindow
?
.
rootViewController
activityViewController
.
popoverPresentationController
?
.
sourceView
=
controller
?
.
view
...
...
printing/ios/Classes/PrintingPlugin.swift
View file @
bbe5dff
...
...
@@ -84,7 +84,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
width
:
CGFloat
((
args
[
"w"
]
as?
NSNumber
)?
.
floatValue
??
0.0
),
height
:
CGFloat
((
args
[
"h"
]
as?
NSNumber
)?
.
floatValue
??
0.0
)
),
andName
:
args
[
"name"
]
as!
String
andName
:
args
[
"name"
]
as!
String
,
subject
:
args
[
"subject"
]
as?
String
,
body
:
args
[
"body"
]
as?
String
)
result
(
NSNumber
(
value
:
1
))
}
else
if
call
.
method
==
"convertHtml"
{
...
...
printing/lib/printing_web.dart
View file @
bbe5dff
...
...
@@ -159,6 +159,9 @@ class PrintingPlugin extends PrintingPlatform {
Uint8List
bytes
,
String
filename
,
Rect
bounds
,
String
?
subject
,
String
?
body
,
List
<
String
>?
emails
,
)
async
{
final
pdfFile
=
html
.
Blob
(
<
Uint8List
>[
Uint8List
.
fromList
(
bytes
)],
...
...
printing/lib/src/interface.dart
View file @
bbe5dff
...
...
@@ -73,11 +73,26 @@ abstract class PrintingPlatform extends PlatformInterface {
/// Opens the native printer picker interface, and returns the URL of the selected printer.
Future
<
Printer
?>
pickPrinter
(
Rect
bounds
);
/// Displays a platform popup to share the Pdf document to another application
/// Displays a platform popup to share the Pdf document to another application.
///
/// [subject] will be the email subject if selected application is email.
///
/// [body] will be the extra text that can be shared along with the Pdf document.
/// For email application [body] will be the email body text.
///
/// [emails] will be the list of emails to which you want to share the Pdf document.
/// If the selected application is email application then the these [emails] will be
/// filled in the to address.
///
/// [subject] and [body] will only work for Android and iOS platforms.
/// [emails] will only work for Android Platform.
Future
<
bool
>
sharePdf
(
Uint8List
bytes
,
String
filename
,
Rect
bounds
,
String
?
subject
,
String
?
body
,
List
<
String
>?
emails
,
);
/// Convert an html document to a pdf data
...
...
printing/lib/src/method_channel.dart
View file @
bbe5dff
...
...
@@ -225,10 +225,16 @@ class MethodChannelPrinting extends PrintingPlatform {
Uint8List
bytes
,
String
filename
,
Rect
bounds
,
String
?
subject
,
String
?
body
,
List
<
String
>?
emails
,
)
async
{
final
params
=
<
String
,
dynamic
>{
'doc'
:
Uint8List
.
fromList
(
bytes
),
'name'
:
filename
,
'subject'
:
subject
,
'body'
:
body
,
'emails'
:
emails
,
'x'
:
bounds
.
left
,
'y'
:
bounds
.
top
,
'w'
:
bounds
.
width
,
...
...
printing/lib/src/pdf_preview.dart
View file @
bbe5dff
...
...
@@ -36,6 +36,9 @@ class PdfPreview extends StatefulWidget {
this
.
useActions
=
true
,
this
.
pages
,
this
.
dynamicLayout
=
true
,
this
.
shareActionExtraBody
,
this
.
shareActionExtraSubject
,
this
.
shareActionExtraEmails
,
})
:
super
(
key:
key
);
/// Called when a pdf document is needed
...
...
@@ -97,6 +100,17 @@ class PdfPreview extends StatefulWidget {
/// channel message while opened.
final
bool
dynamicLayout
;
/// email subject when email application is selected from the share dialog
final
String
?
shareActionExtraSubject
;
/// extra text to share with Pdf document
final
String
?
shareActionExtraBody
;
/// list of email addresses which will be filled automatically if the email application
/// is selected from the share dialog.
/// This will work only for Android platform.
final
List
<
String
>?
shareActionExtraEmails
;
@override
_PdfPreviewState
createState
()
=>
_PdfPreviewState
();
}
...
...
@@ -590,6 +604,9 @@ class _PdfPreviewState extends State<PdfPreview> {
bytes:
bytes
,
bounds:
bounds
,
filename:
widget
.
pdfFileName
??
'document.pdf'
,
body:
widget
.
shareActionExtraBody
,
subject:
widget
.
shareActionExtraSubject
,
emails:
widget
.
shareActionExtraEmails
,
);
if
(
result
&&
widget
.
onShared
!=
null
)
{
...
...
printing/lib/src/printing.dart
View file @
bbe5dff
...
...
@@ -135,11 +135,26 @@ mixin Printing {
);
}
/// Displays a platform popup to share the Pdf document to another application
/// Displays a platform popup to share the Pdf document to another application.
///
/// [subject] will be the email subject if selected application is email.
///
/// [body] will be the extra text that can be shared along with the Pdf document.
/// For email application [body] will be the email body text.
///
/// [emails] will be the list of emails to which you want to share the Pdf document.
/// If the selected application is email application then the these [emails] will be
/// filled in the to address.
///
/// [subject] and [body] will only work for Android and iOS platforms.
/// [emails] will only work for Android Platform.
static
Future
<
bool
>
sharePdf
({
required
Uint8List
bytes
,
String
filename
=
'document.pdf'
,
Rect
?
bounds
,
String
?
subject
,
String
?
body
,
List
<
String
>?
emails
,
})
{
bounds
??=
Rect
.
fromCircle
(
center:
Offset
.
zero
,
radius:
10
);
...
...
@@ -147,6 +162,9 @@ mixin Printing {
bytes
,
filename
,
bounds
,
subject
,
body
,
emails
,
);
}
...
...
printing/pubspec.yaml
View file @
bbe5dff
...
...
@@ -7,7 +7,7 @@ description: >
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/printing
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
5.
0.5
version
:
5.
1.0
environment
:
sdk
:
"
>=2.12.0-0
<3.0.0"
...
...
printing/test/printing_test.dart
View file @
bbe5dff
...
...
@@ -118,7 +118,8 @@ class MockPrinting extends Mock
true
;
@override
Future
<
bool
>
sharePdf
(
Uint8List
bytes
,
String
filename
,
Rect
bounds
)
async
=>
Future
<
bool
>
sharePdf
(
Uint8List
bytes
,
String
filename
,
Rect
bounds
,
String
?
subject
,
String
?
body
,
List
<
String
>?
emails
)
async
=>
true
;
@override
...
...
Please
register
or
login
to post a comment