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
2021-04-30 20:57:57 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f53ed300b978f1f200fb1907386a445ffe672dbe
f53ed300
1 parent
9d95badb
Add TableOfContent Widget
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
2 deletions
demo/assets/document.svg
demo/lib/examples/document.dart
pdf/CHANGELOG.md
pdf/lib/src/pdf/outline.dart
pdf/lib/src/widgets/annotations.dart
pdf/lib/src/widgets/content.dart
pdf/pubspec.yaml
demo/assets/document.svg
0 → 100644
View file @
f53ed30
<?xml version="1.0" encoding="utf-8"?>
<svg
viewBox=
"0 0 150 230"
xmlns=
"http://www.w3.org/2000/svg"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
>
<defs>
<linearGradient
id=
"gradient-1"
>
<stop
offset=
"0"
style=
"stop-color: rgb(255, 255, 255);"
/>
<stop
offset=
"1"
style=
"stop-color: rgb(161, 161, 161);"
/>
</linearGradient>
<linearGradient
id=
"gradient-1-0"
gradientUnits=
"userSpaceOnUse"
x1=
"119.315"
y1=
"36.313"
x2=
"119.315"
y2=
"216.359"
xlink:href=
"#gradient-1"
/>
</defs>
<rect
x=
"-67.203"
y=
"-48.72"
width=
"276.134"
height=
"354.501"
style=
"fill: rgb(93, 32, 205);"
/>
<ellipse
style=
"fill: rgb(141, 81, 252);"
cx=
"119.315"
cy=
"126.336"
rx=
"139.238"
ry=
"98.673"
transform=
"matrix(0.93642, 0.35088, -0.35088, 0.93642, -15.610807, -59.255697)"
/>
<ellipse
style=
"fill: url(#gradient-1-0);"
cx=
"119.315"
cy=
"126.336"
rx=
"130.398"
ry=
"90.023"
transform=
"matrix(0.952861, 0.303408, -0.303408, 0.952861, -26.924128, -56.954295)"
/>
</svg>
...
...
demo/lib/examples/document.dart
View file @
f53ed30
...
...
@@ -28,6 +28,72 @@ Future<Uint8List> generateDocument(
final
font1
=
await
rootBundle
.
load
(
'assets/open-sans.ttf'
);
final
font2
=
await
rootBundle
.
load
(
'assets/open-sans-bold.ttf'
);
final
shape
=
await
rootBundle
.
loadString
(
'assets/document.svg'
);
doc
.
addPage
(
pw
.
Page
(
pageTheme:
pw
.
PageTheme
(
pageFormat:
format
.
copyWith
(
marginBottom:
1.5
*
PdfPageFormat
.
cm
),
orientation:
pw
.
PageOrientation
.
portrait
,
buildBackground:
(
context
)
=>
pw
.
FullPage
(
ignoreMargins:
true
,
child:
pw
.
SvgImage
(
svg:
shape
,
fit:
pw
.
BoxFit
.
fill
),
),
),
build:
(
context
)
{
return
pw
.
Column
(
children:
[
pw
.
Spacer
(),
pw
.
RichText
(
text:
pw
.
TextSpan
(
children:
[
pw
.
TextSpan
(
text:
DateTime
.
now
().
year
.
toString
()
+
'
\n
'
,
style:
pw
.
TextStyle
(
fontWeight:
pw
.
FontWeight
.
bold
,
color:
PdfColors
.
grey600
,
fontSize:
40
,
),
),
pw
.
TextSpan
(
text:
'Portable Document Format'
,
style:
pw
.
TextStyle
(
fontWeight:
pw
.
FontWeight
.
bold
,
fontSize:
40
,
),
),
])),
pw
.
Spacer
(),
pw
.
Container
(
alignment:
pw
.
Alignment
.
topRight
,
height:
150
,
child:
pw
.
PdfLogo
(),
),
pw
.
Spacer
(
flex:
2
),
],
);
},
),
);
doc
.
addPage
(
pw
.
Page
(
pageFormat:
format
.
copyWith
(
marginBottom:
1.5
*
PdfPageFormat
.
cm
),
orientation:
pw
.
PageOrientation
.
portrait
,
build:
(
context
)
{
return
pw
.
Column
(
crossAxisAlignment:
pw
.
CrossAxisAlignment
.
start
,
children:
[
pw
.
Center
(
child:
pw
.
Text
(
'Table of content'
,
style:
pw
.
Theme
.
of
(
context
).
header0
),
),
pw
.
SizedBox
(
height:
20
),
pw
.
TableOfContent
(),
],
);
},
),
);
doc
.
addPage
(
pw
.
MultiPage
(
theme:
pw
.
ThemeData
.
withFont
(
...
...
pdf/CHANGELOG.md
View file @
f53ed30
# Changelog
## 3.
3.1
## 3.
4.0
-
Fix Text.softWrap behavior
-
Add TableOfContent Widget
## 3.3.0
...
...
pdf/lib/src/pdf/outline.dart
View file @
f53ed30
...
...
@@ -58,7 +58,9 @@ class PdfOutline extends PdfObjectDict {
this
.
color
,
this
.
destMode
=
PdfOutlineMode
.
fitPage
,
this
.
style
=
PdfOutlineStyle
.
normal
,
int
?
page
,
})
:
assert
(
anchor
==
null
||
(
dest
==
null
&&
rect
==
null
)),
_page
=
page
,
super
(
pdfDocument
);
/// This holds any outlines below us
...
...
@@ -73,6 +75,12 @@ class PdfOutline extends PdfObjectDict {
/// The destination page
PdfPage
?
dest
;
/// Page number
int
?
get
page
=>
_page
??
(
dest
!=
null
?
pdfDocument
.
pdfPageList
.
pages
.
indexOf
(
dest
!)
+
1
:
null
);
final
int
?
_page
;
/// The region on the destination page
final
PdfRect
?
rect
;
...
...
pdf/lib/src/widgets/annotations.dart
View file @
f53ed30
...
...
@@ -255,6 +255,7 @@ class Outline extends Anchor {
anchor:
name
,
color:
color
,
style:
style
,
page:
context
.
pageNumber
,
);
var
parent
=
context
.
document
.
outline
;
...
...
pdf/lib/src/widgets/content.dart
View file @
f53ed30
...
...
@@ -25,6 +25,7 @@ import 'container.dart';
import
'decoration.dart'
;
import
'flex.dart'
;
import
'geometry.dart'
;
import
'multi_page.dart'
;
import
'text.dart'
;
import
'text_style.dart'
;
import
'theme.dart'
;
...
...
@@ -132,6 +133,49 @@ class Header extends StatelessWidget {
}
}
class
TableOfContent
extends
StatelessWidget
{
Iterable
<
Widget
>
_buildToc
(
PdfOutline
o
,
int
l
)
sync
*
{
for
(
final
c
in
o
.
outlines
)
{
if
(
c
.
title
!=
null
)
{
yield
Padding
(
padding:
const
EdgeInsets
.
only
(
bottom:
2
),
child:
Link
(
destination:
c
.
anchor
!,
child:
Row
(
children:
[
SizedBox
(
width:
10.0
*
l
),
Text
(
'
${c.title}
'
),
SizedBox
(
width:
8
),
Expanded
(
child:
Divider
(
borderStyle:
BorderStyle
.
dotted
,
thickness:
0.2
,
)),
SizedBox
(
width:
8
),
Text
(
'
${c.page}
'
),
],
),
),
);
yield
*
_buildToc
(
c
,
l
+
1
);
}
}
}
@override
Widget
build
(
Context
context
)
{
assert
(
context
.
page
is
!
MultiPage
,
'
$runtimeType
will not work with MultiPage'
);
return
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
...
_buildToc
(
context
.
document
.
outline
,
0
),
],
);
}
}
class
Paragraph
extends
StatelessWidget
{
Paragraph
({
this
.
text
,
...
...
pdf/pubspec.yaml
View file @
f53ed30
...
...
@@ -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
:
3.
3.1
version
:
3.
4.0
environment
:
sdk
:
"
>=2.12.0-0
<3.0.0"
...
...
Please
register
or
login
to post a comment