David PHAM-VAN

Add jpeg image loading function

# 1.3.8
* Add jpeg image loading function
# 1.3.7
* Add Pdf Creation date
* Support 64k glyphs per TTF font
... ...
... ... @@ -62,6 +62,51 @@ class PdfImage extends PdfXObject {
}
}
factory PdfImage.jpeg(PdfDocument pdfDocument, {@required Uint8List image}) {
assert(image != null);
int width;
int height;
int offset = 0;
while (offset < image.length) {
while (image[offset] == 0xff) {
offset++;
}
final int mrkr = image[offset];
offset++;
if (mrkr == 0xd8) {
continue; // SOI
}
if (mrkr == 0xd9) {
break; // EOI
}
if (0xd0 <= mrkr && mrkr <= 0xd7) {
continue;
}
if (mrkr == 0x01) {
continue; // TEM
}
final int len = (image[offset] << 8) | image[offset + 1];
offset += 2;
if (mrkr == 0xc0) {
height = (image[offset + 1] << 8) | image[offset + 2];
width = (image[offset + 3] << 8) | image[offset + 4];
break;
}
offset += len - 2;
}
return PdfImage(pdfDocument,
image: image, width: width, height: height, jpeg: true, alpha: false);
}
/// RGBA Image Data
final Uint8List image;
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 1.3.7
version: 1.3.8
environment:
sdk: ">=2.1.0 <3.0.0"
... ...
... ... @@ -36,12 +36,10 @@ void main() {
final PdfDocument pdf = PdfDocument();
final PdfPage page = PdfPage(pdf, pageFormat: PdfPageFormat.a4);
final PdfImage image = PdfImage(pdf,
image: await download('https://www.nfet.net/nfet.jpg'),
width: 472,
height: 477,
jpeg: true,
alpha: false);
final PdfImage image = PdfImage.jpeg(
pdf,
image: await download('https://www.nfet.net/nfet.jpg'),
);
final PdfGraphics g = page.getGraphics();
g.drawImage(image, 30, page.pageFormat.height - 507.0);
... ...