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-10-17 08:08:32 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4622a0a0ceb203ec4928f5099d87acb87fc969e0
4622a0a0
1 parent
2c619389
Fix Android compilation issues
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
28 deletions
printing/CHANGELOG.md
printing/README.md
printing/android/src/main/java/android/print/PdfConvert.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
printing/pubspec.yaml
printing/CHANGELOG.md
View file @
4622a0a
# Changelog
## 3.6.3
-
Fix Android compilation issues
## 3.6.2
-
Added theme color to dropdown item in pageFormat selector in page preview
...
...
printing/README.md
View file @
4622a0a
...
...
@@ -35,16 +35,6 @@ for documentation.
use_frameworks! # <-- Add this line
```
4.
Set minimum Android version in
`android/app/build.gradle`
:
```
java
defaultConfig
{
...
minSdkVersion
21
// <-- Change this line to 21 or more
...
}
```
## Examples
```
dart
...
...
printing/android/src/main/java/android/print/PdfConvert.java
View file @
4622a0a
...
...
@@ -17,16 +17,20 @@
package
android
.
print
;
import
android.content.Context
;
import
android.os.Build
;
import
android.os.CancellationSignal
;
import
android.os.ParcelFileDescriptor
;
import
android.util.Log
;
import
androidx.annotation.RequiresApi
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
public
class
PdfConvert
{
public
static
void
print
(
final
Context
context
,
final
PrintDocumentAdapter
adapter
,
final
PrintAttributes
attributes
,
final
Result
result
)
{
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
View file @
4622a0a
package
net
.
nfet
.
flutter
.
printing
;
import
android.app.Activity
;
import
android.os.Build
;
import
android.print.PrintAttributes
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.RequiresApi
;
import
java.util.HashMap
;
...
...
@@ -21,15 +23,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
@Override
public
void
onMethodCall
(
@NonNull
MethodCall
call
,
@NonNull
MethodChannel
.
Result
result
)
{
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
KITKAT
)
{
switch
(
call
.
method
)
{
case
"printPdf"
:
{
final
String
name
=
call
.
argument
(
"name"
);
final
Double
width
=
call
.
argument
(
"width"
);
final
Double
height
=
call
.
argument
(
"height"
);
final
Double
marginLeft
=
call
.
argument
(
"marginLeft"
);
final
Double
marginTop
=
call
.
argument
(
"marginTop"
);
final
Double
marginRight
=
call
.
argument
(
"marginRight"
);
final
Double
marginBottom
=
call
.
argument
(
"marginBottom"
);
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
...
...
@@ -70,14 +67,15 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
assert
marginRight
!=
null
;
assert
marginBottom
!=
null
;
PrintAttributes
.
Margins
margins
=
new
PrintAttributes
.
Margins
(
Double
.
valueOf
(
marginLeft
*
1000.0
).
intValue
(),
PrintAttributes
.
Margins
margins
=
new
PrintAttributes
.
Margins
(
Double
.
valueOf
(
marginLeft
*
1000.0
).
intValue
(),
Double
.
valueOf
(
marginTop
*
1000.0
/
72.0
).
intValue
(),
Double
.
valueOf
(
marginRight
*
1000.0
/
72.0
).
intValue
(),
Double
.
valueOf
(
marginBottom
*
1000.0
/
72.0
).
intValue
());
PrintAttributes
.
MediaSize
size
=
new
PrintAttributes
.
MediaSize
(
"flutter_printing"
,
"Provided size"
,
Double
.
valueOf
(
width
*
1000.0
/
72.0
).
intValue
(),
PrintAttributes
.
MediaSize
size
=
new
PrintAttributes
.
MediaSize
(
"flutter_printing"
,
"Provided size"
,
Double
.
valueOf
(
width
*
1000.0
/
72.0
).
intValue
(),
Double
.
valueOf
(
height
*
1000.0
/
72.0
).
intValue
());
printJob
.
convertHtml
((
String
)
call
.
argument
(
"html"
),
size
,
margins
,
...
...
@@ -103,9 +101,13 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
result
.
notImplemented
();
break
;
}
}
else
{
result
.
notImplemented
();
}
}
/// Request the Pdf document from flutter
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onLayout
(
final
PrintingJob
printJob
,
Double
width
,
double
height
,
double
marginLeft
,
double
marginTop
,
double
marginRight
,
double
marginBottom
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
...
...
@@ -141,6 +143,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send completion status to flutter
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onCompleted
(
PrintingJob
printJob
,
boolean
completed
,
String
error
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"completed"
,
completed
);
...
...
@@ -152,6 +155,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send html to pdf data result to flutter
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onHtmlRendered
(
PrintingJob
printJob
,
byte
[]
pdfData
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"doc"
,
pdfData
);
...
...
@@ -161,6 +165,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send html to pdf conversion error to flutter
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onHtmlError
(
PrintingJob
printJob
,
String
error
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"error"
,
error
);
...
...
@@ -170,6 +175,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send pdf to raster data result to flutter
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onPageRasterized
(
PrintingJob
printJob
,
byte
[]
imageData
,
int
width
,
int
height
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"image"
,
imageData
);
...
...
@@ -180,6 +186,8 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
channel
.
invokeMethod
(
"onPageRasterized"
,
args
);
}
/// The page has been converted to an image
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
void
onPageRasterEnd
(
PrintingJob
printJob
)
{
HashMap
<
String
,
Object
>
args
=
new
HashMap
<>();
args
.
put
(
"job"
,
printJob
.
index
);
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
View file @
4622a0a
...
...
@@ -18,20 +18,35 @@ package net.nfet.flutter.printing;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
import
android.content.res.Configuration
;
import
android.graphics.Bitmap
;
import
android.graphics.Matrix
;
import
android.graphics.pdf.PdfRenderer
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.CancellationSignal
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.ParcelFileDescriptor
;
import
android.print.PageRange
;
import
android.print.PdfConvert
;
import
android.print.PrintAttributes
;
import
android.print.PrintDocumentAdapter
;
import
android.print.PrintDocumentInfo
;
import
android.print.PrintJob
;
import
android.print.PrintJobInfo
;
import
android.print.PrintManager
;
import
android.util.Log
;
import
android.webkit.WebView
;
import
android.webkit.WebViewClient
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.RequiresApi
;
import
androidx.core.content.FileProvider
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
...
...
@@ -39,16 +54,12 @@ import java.io.IOException;
import
java.io.OutputStream
;
import
java.nio.ByteBuffer
;
import
java.util.HashMap
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ProviderInfo
;
import
android.content.pm.ResolveInfo
;
import
java.util.List
;
/**
* PrintJob
*/
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
public
class
PrintingJob
extends
PrintDocumentAdapter
{
private
static
PrintManager
printManager
;
private
final
Context
context
;
...
...
@@ -216,11 +227,14 @@ public class PrintingJob extends PrintDocumentAdapter {
shareIntent
.
putExtra
(
Intent
.
EXTRA_STREAM
,
apkURI
);
shareIntent
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
Intent
chooserIntent
=
Intent
.
createChooser
(
shareIntent
,
null
);
List
<
ResolveInfo
>
resInfoList
=
context
.
getPackageManager
().
queryIntentActivities
(
chooserIntent
,
PackageManager
.
MATCH_DEFAULT_ONLY
);
List
<
ResolveInfo
>
resInfoList
=
context
.
getPackageManager
().
queryIntentActivities
(
chooserIntent
,
PackageManager
.
MATCH_DEFAULT_ONLY
);
for
(
ResolveInfo
resolveInfo
:
resInfoList
)
{
String
packageName
=
resolveInfo
.
activityInfo
.
packageName
;
context
.
grantUriPermission
(
packageName
,
apkURI
,
Intent
.
FLAG_GRANT_WRITE_URI_PERMISSION
|
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
context
.
grantUriPermission
(
packageName
,
apkURI
,
Intent
.
FLAG_GRANT_WRITE_URI_PERMISSION
|
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
}
context
.
startActivity
(
chooserIntent
);
shareFile
.
deleteOnExit
();
...
...
printing/pubspec.yaml
View file @
4622a0a
...
...
@@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to
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
:
3.6.
2
version
:
3.6.
3
environment
:
sdk
:
"
>=2.3.0
<3.0.0"
...
...
Please
register
or
login
to post a comment