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
2018-12-22 10:28:25 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ad2334b306d0f4d249f48f8e5d96bdc6dff44942
ad2334b3
1 parent
fd1e2607
Add support for Jpeg Images
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
2 deletions
pdf/CHANGELOG.md
pdf/lib/src/image.dart
pdf/lib/src/object_stream.dart
pdf/test/jpeg_test.dart
pdf/CHANGELOG.md
View file @
ad2334b
...
...
@@ -6,6 +6,7 @@
*
Implement default fonts bounding box
*
Add Bézier Curve primitive
*
Implement drawShape
*
Add support for Jpeg images
# 1.0.8
*
Fix monospace TTF font loading
...
...
pdf/lib/src/image.dart
View file @
ad2334b
...
...
@@ -36,6 +36,9 @@ class PdfImage extends PdfXObject {
/// Process alphaChannel only
final
bool
alphaChannel
;
/// The image data is a jpeg image
final
bool
jpeg
;
/// Creates a new [PdfImage] instance.
///
/// @param imgage an [Uint8List] value
...
...
@@ -48,7 +51,8 @@ class PdfImage extends PdfXObject {
@required
this
.
width
,
@required
this
.
height
,
this
.
alpha
=
true
,
this
.
alphaChannel
=
false
})
this
.
alphaChannel
=
false
,
this
.
jpeg
=
false
})
:
assert
(
alphaChannel
==
false
||
alpha
==
true
),
assert
(
width
!=
null
),
assert
(
height
!=
null
),
...
...
@@ -74,10 +78,21 @@ class PdfImage extends PdfXObject {
}
else
{
params
[
"/ColorSpace"
]
=
PdfStream
.
string
(
"/DeviceRGB"
);
}
if
(
jpeg
)
{
params
[
"/Intent"
]
=
PdfStream
.
string
(
"/RelativeColorimetric"
);
}
}
@override
void
_prepare
()
{
if
(
jpeg
)
{
buf
.
putBytes
(
image
);
params
[
"/Filter"
]
=
PdfStream
.
string
(
"/DCTDecode"
);
super
.
_prepare
();
return
;
}
// write the pixels to the stream
// print("Processing image ${img.width}x${img.height} pixels");
...
...
pdf/lib/src/object_stream.dart
View file @
ad2334b
...
...
@@ -41,7 +41,10 @@ class PdfObjectStream extends PdfObject {
void
_prepare
()
{
super
.
_prepare
();
if
(
pdfDocument
.
deflate
!=
null
)
{
if
(
params
.
containsKey
(
"/Filter"
))
{
// The data is already in the right format
_data
=
buf
.
output
();
}
else
if
(
pdfDocument
.
deflate
!=
null
)
{
_data
=
pdfDocument
.
deflate
(
buf
.
output
());
params
[
"/Filter"
]
=
PdfStream
.
string
(
"/FlateDecode"
);
}
else
if
(
isBinary
)
{
...
...
pdf/test/jpeg_test.dart
0 → 100644
View file @
ad2334b
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:pdf/pdf.dart'
;
import
"package:test/test.dart"
;
Future
<
Uint8List
>
download
(
String
url
)
async
{
var
client
=
HttpClient
();
var
request
=
await
client
.
getUrl
(
Uri
.
parse
(
url
));
var
response
=
await
request
.
close
();
var
builder
=
await
response
.
fold
(
BytesBuilder
(),
(
b
,
d
)
=>
b
..
add
(
d
));
var
data
=
builder
.
takeBytes
();
return
Uint8List
.
fromList
(
data
);
}
void
main
(
)
{
test
(
'Pdf1'
,
()
async
{
var
pdf
=
PdfDocument
();
var
page
=
PdfPage
(
pdf
,
pageFormat:
PdfPageFormat
.
a4
);
var
image
=
PdfImage
(
pdf
,
image:
await
download
(
"https://www.nfet.net/nfet.jpg"
),
width:
472
,
height:
477
,
jpeg:
true
,
alpha:
false
);
var
g
=
page
.
getGraphics
();
g
.
drawImage
(
image
,
30.0
,
page
.
pageFormat
.
height
-
507.0
);
var
file
=
File
(
'file4.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
});
}
...
...
Please
register
or
login
to post a comment