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-08-21 09:14:48 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b73f717d2075056526df625cc9c93c36715284c1
b73f717d
1 parent
c1539c90
Remove dependency to dart:io for web
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
44 additions
and
32 deletions
pdf/CHANGELOG.md
pdf/example/main.dart
pdf/lib/pdf.dart
pdf/lib/src/ascii85.dart
pdf/lib/src/document.dart
pdf/lib/src/object_stream.dart
pdf/lib/src/stream.dart
pdf/pubspec.yaml
pdf/test/complex_test.dart
pdf/test/minimal_test.dart
pdf/test/ttf_test.dart
printing/CHANGELOG.md
printing/example/main.dart
printing/pubspec.yaml
pdf/CHANGELOG.md
View file @
b73f717
# 1.0.5
*
Remove dependency to dart:io
*
Add Contributing
# 1.0.4
*
Updated homepage
*
Update source formatting
...
...
pdf/example/main.dart
View file @
b73f717
...
...
@@ -3,7 +3,7 @@ import 'dart:io';
import
'package:pdf/pdf.dart'
;
void
main
(
)
{
final
pdf
=
new
PDFDocument
();
final
pdf
=
new
PDFDocument
(
deflate:
zlib
.
encode
);
final
page
=
new
PDFPage
(
pdf
,
pageFormat:
PDFPageFormat
.
LETTER
);
final
g
=
page
.
getGraphics
();
final
font
=
new
PDFFont
(
pdf
);
...
...
pdf/lib/pdf.dart
View file @
b73f717
...
...
@@ -19,7 +19,6 @@
library
pdf
;
import
'dart:convert'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:meta/meta.dart'
;
...
...
pdf/lib/src/ascii85.dart
View file @
b73f717
...
...
@@ -18,8 +18,8 @@
part of
pdf
;
class
Ascii85Encoder
extends
Converter
<
Uint8List
,
Uint8List
>
{
Uint8List
convert
(
Uint8List
input
)
{
class
Ascii85Encoder
extends
Converter
<
List
<
int
>,
List
<
int
>>
{
List
<
int
>
convert
(
List
<
int
>
input
)
{
Uint8List
buffer
=
new
Uint8List
(
_maxEncodedLen
(
input
.
length
)
+
2
);
var
b
=
0
;
...
...
pdf/lib/src/document.dart
View file @
b73f717
...
...
@@ -37,6 +37,8 @@ enum PDFPageMode {
FULLSCREEN
}
typedef
List
<
int
>
DeflateCallback
(
List
<
int
>
data
);
/// <p>This class is the base of the PDF generator. A PDFDocument class is
/// created for a document, and each page, object, annotation,
/// etc is added to the document.
...
...
@@ -66,8 +68,10 @@ class PDFDocument {
/// It's only used when the document is being written.
PDFObject
defaultOutlineBorder
;
/// True if we will compress the stream in the pdf file
final
bool
deflate
;
/// Callback to compress the stream in the pdf file.
/// Use `deflate: zlib.encode` if using dart:io
/// No compression by default
final
DeflateCallback
deflate
;
/// <p>
/// These map the page modes just defined to the pagemodes setting of PDF.
...
...
@@ -88,7 +92,7 @@ class PDFDocument {
/// <p>This creates a PDF document</p>
/// @param pagemode an int, determines how the document will present itself to
/// the viewer when it first opens.
PDFDocument
({
PDFPageMode
pageMode
=
PDFPageMode
.
NONE
,
this
.
deflate
=
true
})
{
PDFDocument
({
PDFPageMode
pageMode
=
PDFPageMode
.
NONE
,
this
.
deflate
})
{
_objser
=
1
;
// Now create some standard objects
...
...
@@ -141,7 +145,7 @@ class PDFDocument {
pos
.
close
();
}
Uint8List
save
()
{
List
<
int
>
save
()
{
PDFStream
os
=
new
PDFStream
();
write
(
os
);
return
os
.
output
();
...
...
pdf/lib/src/object_stream.dart
View file @
b73f717
...
...
@@ -34,15 +34,14 @@ class PDFObjectStream extends PDFObject {
PDFObjectStream
(
PDFDocument
pdfDocument
,
{
String
type
,
this
.
isBinary
=
false
})
:
super
(
pdfDocument
,
type
);
Uint8List
_data
;
List
<
int
>
_data
;
@override
void
prepare
()
{
super
.
prepare
();
if
(
pdfDocument
.
deflate
)
{
var
z
=
new
ZLibCodec
(
level:
ZLibOption
.
maxLevel
);
_data
=
z
.
encode
(
buf
.
output
());
if
(
pdfDocument
.
deflate
!=
null
)
{
_data
=
pdfDocument
.
deflate
(
buf
.
output
());
params
[
"/Filter"
]
=
PDFStream
.
string
(
"/FlateDecode"
);
}
else
if
(
isBinary
)
{
// This is a Ascii85 stream
...
...
pdf/lib/src/stream.dart
View file @
b73f717
...
...
@@ -19,18 +19,18 @@
part of
pdf
;
class
PDFStream
{
final
_stream
=
new
BytesBuilder
(
copy:
false
);
final
_stream
=
List
<
int
>(
);
void
putStream
(
PDFStream
s
)
{
_stream
.
add
(
s
.
_stream
.
toBytes
()
);
_stream
.
add
All
(
s
.
_stream
);
}
void
putString
(
String
s
)
{
for
(
int
codeUnit
in
s
.
codeUnits
)
{
if
(
codeUnit
<=
0x7f
)
{
_stream
.
add
Byte
(
codeUnit
);
_stream
.
add
(
codeUnit
);
}
else
{
_stream
.
add
Byte
(
0x20
);
_stream
.
add
(
0x20
);
}
}
}
...
...
@@ -39,13 +39,13 @@ class PDFStream {
void
putStringUtf16
(
String
s
)
{
for
(
int
codeUnit
in
s
.
codeUnits
)
{
_stream
.
addByte
(
codeUnit
&
0xff
);
_stream
.
addByte
((
codeUnit
>>
8
)
&
0xff
);
_stream
.
add
(
codeUnit
&
0xff
);
_stream
.
add
((
codeUnit
>>
8
)
&
0xff
);
}
}
void
putBytes
(
List
<
int
>
s
)
{
_stream
.
add
(
s
);
_stream
.
add
All
(
s
);
}
void
putNum
(
double
d
)
{
...
...
@@ -135,5 +135,5 @@ class PDFStream {
int
get
offset
=>
_stream
.
length
;
Uint8List
output
()
=>
_stream
.
toBytes
()
;
List
<
int
>
output
()
=>
_stream
;
}
...
...
pdf/pubspec.yaml
View file @
b73f717
...
...
@@ -2,7 +2,7 @@ name: pdf
author
:
David PHAM-VAN <dev.nfet.net@gmail.com>
description
:
A pdf producer for Dart. It can create pdf files for both web or flutter.
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/pdf
version
:
1.0.
4
version
:
1.0.
5
environment
:
sdk
:
"
>=1.8.0
<3.0.0"
...
...
pdf/test/complex_test.dart
View file @
b73f717
...
...
@@ -8,10 +8,11 @@ import 'package:vector_math/vector_math_64.dart';
void
main
(
)
{
test
(
'Pdf'
,
()
{
// Image img = new Image(10, 10);
// img.fill(0x12345678);
var
img
=
new
Uint32List
(
10
*
10
);
print
(
img
.
length
);
img
.
fillRange
(
0
,
img
.
length
-
1
,
0x12345678
);
var
pdf
=
new
PDFDocument
(
deflate:
fals
e
);
var
pdf
=
new
PDFDocument
(
deflate:
zlib
.
encod
e
);
var
i
=
pdf
.
info
;
i
.
author
=
"David PHAM-VAN"
;
i
.
creator
=
i
.
author
;
...
...
@@ -50,8 +51,8 @@ void main() {
g
.
drawRect
(
300.0
,
150.0
,
50.0
,
50.0
);
g
.
fillPath
();
g
.
setColor
(
new
PDFColor
(
0.0
,
0.5
,
0.0
));
// var image = new PDFImage(pdf,
// image: img.data.buffer.asUint8List(), width: img.width, height: img.height);
var
image
=
new
PDFImage
(
pdf
,
image:
img
.
buffer
.
asUint8List
(),
width:
10
,
height:
10
);
for
(
var
i
=
10.0
;
i
<
90.0
;
i
+=
5.0
)
{
g
.
saveContext
();
var
tm
=
new
Matrix4
.
identity
();
...
...
@@ -59,7 +60,7 @@ void main() {
tm
.
translate
(
300.0
,
-
100.0
);
g
.
setTransform
(
tm
);
g
.
drawString
(
font1
,
12.0
,
"Hello
$i
"
,
20.0
,
100.0
);
// g.drawImage(image, 100.0, 100.0, 8
0.0);
g
.
drawImage
(
image
,
100.0
,
10
0.0
);
g
.
restoreContext
();
}
...
...
pdf/test/minimal_test.dart
View file @
b73f717
...
...
@@ -5,7 +5,7 @@ import "package:test/test.dart";
void
main
(
)
{
test
(
'Pdf1'
,
()
{
var
pdf
=
new
PDFDocument
(
deflate:
false
);
var
pdf
=
new
PDFDocument
();
var
page
=
new
PDFPage
(
pdf
,
pageFormat:
PDFPageFormat
.
A4
);
var
g
=
page
.
getGraphics
();
...
...
pdf/test/ttf_test.dart
View file @
b73f717
...
...
@@ -6,7 +6,7 @@ import 'package:test/test.dart';
void
main
(
)
{
test
(
'Pdf'
,
()
{
var
pdf
=
new
PDFDocument
(
deflate:
false
);
var
pdf
=
new
PDFDocument
();
var
i
=
pdf
.
info
;
i
.
author
=
"David PHAM-VAN"
;
i
.
creator
=
i
.
author
;
...
...
printing/CHANGELOG.md
View file @
b73f717
# 1.0.4
*
Update example for pdf 1.0.5
*
Add Contributing
# 1.0.3
*
Update source formatting
*
Update README
...
...
printing/example/main.dart
View file @
b73f717
import
'dart:io'
;
import
'dart:ui'
;
import
'package:flutter/material.dart'
;
...
...
@@ -10,7 +11,7 @@ class MyApp extends StatelessWidget {
final
shareWidget
=
new
GlobalKey
();
PDFDocument
_generateDocument
()
{
final
pdf
=
new
PDFDocument
();
final
pdf
=
new
PDFDocument
(
deflate:
zlib
.
encode
);
final
page
=
new
PDFPage
(
pdf
,
pageFormat:
PDFPageFormat
.
A4
);
final
g
=
page
.
getGraphics
();
final
font
=
new
PDFFont
(
pdf
);
...
...
printing/pubspec.yaml
View file @
b73f717
...
...
@@ -2,7 +2,7 @@ name: printing
author
:
David PHAM-VAN <dev.nfet.net@gmail.com>
description
:
Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/printing
version
:
1.0.
3
version
:
1.0.
4
environment
:
sdk
:
"
>=1.19.0
<3.0.0"
...
...
@@ -10,7 +10,7 @@ environment:
dependencies
:
flutter
:
sdk
:
flutter
pdf
:
"
^1.0.
3
"
pdf
:
"
^1.0.
5
"
flutter
:
plugin
:
...
...
Please
register
or
login
to post a comment