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-03-12 07:15:29 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e6fc22e417e1d6f510c21cac82fbfd6ebf03acb6
e6fc22e4
1 parent
fcefd757
Update example tab
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
printing/CHANGELOG.md
printing/example/README.md
printing/CHANGELOG.md
View file @
e6fc22e
...
...
@@ -7,6 +7,7 @@
-
Use plugin_platform_interface
-
Fix inconsistent API
-
Add Unit tests
-
Update example tab
## 3.1.0
...
...
printing/example/README.md
View file @
e6fc22e
...
...
@@ -4,7 +4,7 @@
import
'package:flutter/material.dart'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
as
p
df
;
import
'package:pdf/widgets.dart'
as
p
w
;
import
'package:printing/printing.dart'
;
void
main
(
)
=>
runApp
(
MyApp
());
...
...
@@ -15,43 +15,51 @@ class MyApp extends StatelessWidget {
return
MaterialApp
(
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Printing Demo'
),
title:
Text
(
'Printing Demo'
),
),
floatingActionButton:
FloatingActionButton
(
child:
const
Icon
(
Icons
.
print
),
child:
Icon
(
Icons
.
print
),
tooltip:
'Print Document'
,
onPressed:
()
{
// This is where we print the document
Printing
.
layoutPdf
(
onLayout:
buildPdf
,
// [onLayout] will be called multiple times
// when the user changes the printer or printer settings
onLayout:
(
PdfPageFormat
format
)
{
// Any valid Pdf document can be returned here as a list of int
return
buildPdf
(
format
);
},
);
},
),
body:
Center
(
child:
const
Text
(
'Click on the print button below'
),
child:
Text
(
'Click on the print button below'
),
),
),
);
}
/// This method takes a page format and generates the Pdf file data
List
<
int
>
buildPdf
(
PdfPageFormat
format
)
{
final
Document
doc
=
Document
();
// Create the Pdf document
final
pw
.
Document
doc
=
pw
.
Document
();
// Add one page with centered text "Hello World"
doc
.
addPage
(
p
df
.
Page
(
p
w
.
Page
(
pageFormat:
format
,
build:
(
pdf
.
Context
context
)
{
return
pdf
.
ConstrainedBox
(
constraints:
const
pdf
.
BoxConstraints
.
expand
(),
child:
pdf
.
FittedBox
(
child:
pdf
.
Text
(
'Hello World'
,
),
build:
(
pw
.
Context
context
)
{
return
pw
.
ConstrainedBox
(
constraints:
pw
.
BoxConstraints
.
expand
(),
child:
pw
.
FittedBox
(
child:
pw
.
Text
(
'Hello World'
),
),
);
},
),
);
// Build and return the final Pdf file data
return
doc
.
save
();
}
}
...
...
Please
register
or
login
to post a comment