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-02-21 07:38:43 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
df004fbd6ad29572c0ae981cee364969ae7bf336
df004fbd
1 parent
bb57f395
Add a filename parameter for sharing
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
16 deletions
printing/CHANGELOG.md
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
printing/example/lib/main.dart
printing/ios/Classes/PrintingPlugin.m
printing/lib/src/printing.dart
printing/CHANGELOG.md
View file @
df004fb
# 1.3.4
*
Fix dart lint warnings
*
Add documentation
*
Add a filename parameter for sharing
# 1.3.3
*
Update Readme
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
View file @
df004fb
...
...
@@ -152,7 +152,7 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa
result
.
success
(
0
);
break
;
case
"sharePdf"
:
sharePdf
((
byte
[])
call
.
argument
(
"doc"
));
sharePdf
((
byte
[])
call
.
argument
(
"doc"
)
,
(
String
)
call
.
argument
(
"name"
)
);
result
.
success
(
0
);
break
;
default
:
...
...
@@ -161,11 +161,16 @@ public class PrintingPlugin extends PrintDocumentAdapter implements MethodCallHa
}
}
private
void
sharePdf
(
byte
[]
data
)
{
private
void
sharePdf
(
byte
[]
data
,
String
name
)
{
try
{
final
File
externalFilesDirectory
=
activity
.
getExternalFilesDir
(
Environment
.
DIRECTORY_PICTURES
);
File
shareFile
=
File
.
createTempFile
(
"document"
,
".pdf"
,
externalFilesDirectory
);
activity
.
getExternalFilesDir
(
Environment
.
DIRECTORY_DOCUMENTS
);
File
shareFile
;
if
(
name
==
null
)
{
shareFile
=
File
.
createTempFile
(
"document-"
,
".pdf"
,
externalFilesDirectory
);
}
else
{
shareFile
=
new
File
(
externalFilesDirectory
,
name
);
}
FileOutputStream
stream
=
new
FileOutputStream
(
shareFile
);
stream
.
write
(
data
);
...
...
printing/example/lib/main.dart
View file @
df004fb
...
...
@@ -44,7 +44,7 @@ class MyAppState extends State<MyApp> {
referenceBox
.
localToGlobal
(
referenceBox
.
paintBounds
.
bottomRight
);
final
Rect
bounds
=
Rect
.
fromPoints
(
topLeft
,
bottomRight
);
Printing
.
sharePdf
(
document:
pdf
,
bounds:
bounds
);
Printing
.
sharePdf
(
document:
pdf
,
filename:
'my-résumé.pdf'
,
bounds:
bounds
);
}
Future
<
void
>
_printScreen
()
async
{
...
...
printing/ios/Classes/PrintingPlugin.m
View file @
df004fb
...
...
@@ -50,7 +50,8 @@
[[
call
.
arguments
objectForKey
:
@"x"
]
floatValue
],
[[
call
.
arguments
objectForKey
:
@"y"
]
floatValue
],
[[
call
.
arguments
objectForKey
:
@"w"
]
floatValue
],
[[
call
.
arguments
objectForKey
:
@"h"
]
floatValue
])];
[[
call
.
arguments
objectForKey
:
@"h"
]
floatValue
])
andName
:
[
call
.
arguments
objectForKey
:
@"name"
]];
result
(
@1
);
}
else
{
result
(
FlutterMethodNotImplemented
);
...
...
@@ -92,21 +93,27 @@
}
-
(
void
)
sharePdf
:
(
nonnull
FlutterStandardTypedData
*
)
data
withSourceRect
:
(
CGRect
)
rect
{
withSourceRect
:
(
CGRect
)
rect
andName
:
(
NSString
*
)
name
{
NSURL
*
tmpDirURL
=
[
NSURL
fileURLWithPath
:
NSTemporaryDirectory
()
isDirectory
:
YES
];
CFUUIDRef
uuid
=
CFUUIDCreate
(
NULL
);
assert
(
uuid
!=
NULL
);
assert
(
uuid
!=
nil
);
CFStringRef
uuidStr
=
CFUUIDCreateString
(
NULL
,
uuid
);
assert
(
uuidStr
!=
NULL
);
NSURL
*
fileURL
=
[[
tmpDirURL
URLByAppendingPathComponent
:[
NSString
stringWithFormat
:
@"pdf-%@"
,
uuidStr
]]
URLByAppendingPathExtension
:
@"pdf"
];
assert
(
fileURL
!=
NULL
);
assert
(
uuidStr
!=
nil
);
NSURL
*
fileURL
;
if
([
name
isEqual
:[
NSNull
null
]])
{
fileURL
=
[[
tmpDirURL
URLByAppendingPathComponent
:[
NSString
stringWithFormat
:
@"document-%@"
,
uuidStr
]]
URLByAppendingPathExtension
:
@"pdf"
];
}
else
{
fileURL
=
[
tmpDirURL
URLByAppendingPathComponent
:
name
];
}
assert
(
fileURL
!=
nil
);
CFRelease
(
uuidStr
);
CFRelease
(
uuid
);
...
...
printing/lib/src/printing.dart
View file @
df004fb
...
...
@@ -65,7 +65,10 @@ mixin Printing {
/// Displays a platform popup to share the Pdf document to another application
static
Future
<
void
>
sharePdf
(
{
PdfDocument
document
,
List
<
int
>
bytes
,
Rect
bounds
})
async
{
{
PdfDocument
document
,
List
<
int
>
bytes
,
String
filename
,
Rect
bounds
})
async
{
assert
(
document
!=
null
||
bytes
!=
null
);
assert
(!(
document
==
null
&&
bytes
==
null
));
...
...
@@ -77,6 +80,7 @@ mixin Printing {
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'doc'
:
Uint8List
.
fromList
(
bytes
),
'name'
:
filename
,
'x'
:
bounds
.
left
,
'y'
:
bounds
.
top
,
'w'
:
bounds
.
width
,
...
...
Please
register
or
login
to post a comment