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-07-24 15:18:54 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b215533be2367cd37c9e8c29338b66c48d88f228
b215533b
1 parent
89e61350
Uses better page format object
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
55 deletions
example/main.dart
lib/src/page.dart
lib/src/page_format.dart
test/pdf1_test.dart
test/pdf_test.dart
example/main.dart
View file @
b215533
...
...
@@ -4,7 +4,7 @@ import 'package:pdf/pdf.dart';
void
main
(
)
{
final
pdf
=
new
PDFDocument
();
final
page
=
new
PDFPage
(
pdf
,
pageFormat:
new
PDFPageFormat
(
PDFPageFormat
.
LETTER
)
);
final
page
=
new
PDFPage
(
pdf
,
pageFormat:
PDFPageFormat
.
LETTER
);
final
g
=
page
.
getGraphics
();
final
font
=
new
PDFFont
(
pdf
);
...
...
lib/src/page.dart
View file @
b215533
...
...
@@ -48,11 +48,9 @@ class PDFPage extends PDFObject {
/// @see PageFormat#LANDSCAPE
/// @see PageFormat#REVERSE_LANDSCAPE
/// @param pageFormat PageFormat describing the page size
PDFPage
(
PDFDocument
pdfDocument
,
{
int
orientation
,
this
.
pageFormat
})
:
super
(
pdfDocument
,
"/Page"
)
{
PDFPage
(
PDFDocument
pdfDocument
,
{
this
.
pageFormat
})
:
super
(
pdfDocument
,
"/Page"
)
{
pdfDocument
.
pdfPageList
.
pages
.
add
(
this
);
if
(
pageFormat
==
null
)
pageFormat
=
new
PDFPageFormat
();
setOrientation
(
orientation
);
if
(
pageFormat
==
null
)
pageFormat
=
PDFPageFormat
.
A4
;
}
/// This returns a PDFGraphics object, which can then be used to render
...
...
@@ -76,25 +74,7 @@ class PDFPage extends PDFObject {
/// Gets the dimensions of the page.
/// @return a Dimension object containing the width and height of the page.
PDFPoint
getDimension
()
=>
new
PDFPoint
(
pageFormat
.
getWidth
(),
pageFormat
.
getHeight
());
/// Sets the page's orientation.
///
/// <p>Normally, this should be done when the page is created, to avoid
/// problems.
///
/// @param orientation a PageFormat orientation constant:
/// PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE
void
setOrientation
(
int
orientation
)
{
pageFormat
.
setOrientation
(
orientation
);
}
/// Returns the pages orientation:
/// PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE
///
/// @see java.awt.print.PageFormat
/// @return current orientation of the page
int
getOrientation
()
=>
pageFormat
.
getOrientation
();
PDFPoint
getDimension
()
=>
new
PDFPoint
(
pageFormat
.
width
,
pageFormat
.
height
);
/// This adds an Annotation to the page.
///
...
...
@@ -173,7 +153,7 @@ class PDFPage extends PDFObject {
// the /MediaBox for the page size
params
[
"/MediaBox"
]
=
new
PDFStream
()
..
putStringArray
([
0
,
0
,
pageFormat
.
getWidth
(),
pageFormat
.
getHeight
()
]);
..
putStringArray
([
0
,
0
,
pageFormat
.
width
,
pageFormat
.
height
]);
// Rotation (if not zero)
// if(rotate!=0) {
...
...
@@ -237,5 +217,5 @@ class PDFPage extends PDFObject {
/// @param x Coordinate in Java space
/// @param y Coordinate in Java space
/// @return array containing the x & y Coordinate in User space
PDFPoint
cxy
(
double
x
,
double
y
)
=>
new
PDFPoint
(
x
,
pageFormat
.
getHeight
()
-
y
);
PDFPoint
cxy
(
double
x
,
double
y
)
=>
new
PDFPoint
(
x
,
pageFormat
.
height
-
y
);
}
...
...
lib/src/page_format.dart
View file @
b215533
...
...
@@ -19,38 +19,19 @@
part of
pdf
;
class
PDFPageFormat
{
static
const
A4
=
const
[
595.28
,
841.89
];
static
const
A3
=
const
[
841.89
,
1190.55
];
static
const
A5
=
const
[
420.94
,
595.28
];
static
const
LETTER
=
const
[
612.0
,
792.0
];
static
const
LEGAL
=
const
[
612.0
,
1008.0
];
static
const
A4
=
const
PDFPageFormat
(
595.28
,
841.89
);
static
const
A3
=
const
PDFPageFormat
(
841.89
,
1190.55
);
static
const
A5
=
const
PDFPageFormat
(
420.94
,
595.28
);
static
const
LETTER
=
const
PDFPageFormat
(
612.0
,
792.0
);
static
const
LEGAL
=
const
PDFPageFormat
(
612.0
,
1008.0
);
static
const
PT
=
1.0
;
static
const
IN
=
72.0
;
static
const
CM
=
IN
/
2.54
;
static
const
MM
=
IN
/
25.4
;
double
width
;
double
height
;
double
imageableX
=
10.0
;
double
imageableY
=
10.0
;
double
imageableWidth
=
300.0
;
double
imageableHeight
=
300.0
;
int
orientation
=
0
;
final
double
width
;
final
double
height
;
PDFPageFormat
([
List
<
double
>
format
])
{
if
(
format
==
null
||
format
.
length
!=
2
)
format
=
A4
;
width
=
format
[
0
];
height
=
format
[
1
];
}
double
getWidth
()
=>
width
;
double
getHeight
()
=>
height
;
void
setOrientation
(
int
orientation
)
{
this
.
orientation
=
orientation
;
}
int
getOrientation
()
=>
orientation
;
const
PDFPageFormat
(
this
.
width
,
this
.
height
);
}
...
...
test/pdf1_test.dart
View file @
b215533
...
...
@@ -6,7 +6,7 @@ import "package:test/test.dart";
void
main
(
)
{
test
(
'Pdf1'
,
()
{
var
pdf
=
new
PDFDocument
(
deflate:
false
);
var
page
=
new
PDFPage
(
pdf
,
pageFormat:
new
PDFPageFormat
(
PDFPageFormat
.
A4
)
);
var
page
=
new
PDFPage
(
pdf
,
pageFormat:
PDFPageFormat
.
A4
);
var
g
=
page
.
getGraphics
();
g
.
drawLine
(
30.0
,
30.0
,
200.0
,
200.0
);
...
...
test/pdf_test.dart
View file @
b215533
...
...
@@ -16,7 +16,7 @@ void main() {
i
.
creator
=
i
.
author
;
i
.
title
=
"My Title"
;
i
.
subject
=
"My Subject"
;
var
page
=
new
PDFPage
(
pdf
,
pageFormat:
new
PDFPageFormat
([
500.0
,
300.0
]
));
var
page
=
new
PDFPage
(
pdf
,
pageFormat:
const
PDFPageFormat
(
500.0
,
300.0
));
var
g
=
page
.
getGraphics
();
g
.
saveContext
();
...
...
Please
register
or
login
to post a comment