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-16 17:28:23 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5036ac15a0682fee639df50feb38b2faa4280d44
5036ac15
1 parent
ea988422
Run dartfmt on sources
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
69 additions
and
30 deletions
CHANGELOG.md
test/example.dart → example/main.dart
lib/pdf.dart
lib/src/annotation.dart
lib/src/border.dart
lib/src/catalog.dart
lib/src/color.dart
lib/src/document.dart
lib/src/font.dart
lib/src/font_descriptor.dart
lib/src/formxobject.dart
lib/src/graphics.dart
lib/src/info.dart
lib/src/outline.dart
lib/src/page.dart
lib/src/stream.dart
lib/src/ttffont.dart
lib/src/xref.dart
CHANGELOG.md
0 → 100644
View file @
5036ac1
*
Add example
...
...
test/example
.dart →
example/main
.dart
View file @
5036ac1
lib/pdf.dart
View file @
5036ac1
...
...
@@ -64,4 +64,3 @@ part 'src/stream.dart';
part
'src/ttffont.dart'
;
part
'src/xobject.dart'
;
part
'src/xref.dart'
;
...
...
lib/src/annotation.dart
View file @
5036ac1
...
...
@@ -59,7 +59,18 @@ class PDFAnnot extends PDFObject {
PDFBorder
border
;
PDFAnnot
(
PDFPage
pdfPage
,
{
String
type
,
this
.
s
,
this
.
l
,
this
.
b
,
this
.
r
,
this
.
t
,
this
.
subtype
,
this
.
dest
,
this
.
fl
,
this
.
fb
,
this
.
fr
,
this
.
ft
})
{
String
type
,
this
.
s
,
this
.
l
,
this
.
b
,
this
.
r
,
this
.
t
,
this
.
subtype
,
this
.
dest
,
this
.
fl
,
this
.
fb
,
this
.
fr
,
this
.
ft
})
:
super
(
pdfPage
.
pdfDocument
,
type
)
{
pdfPage
.
annotations
.
add
(
this
);
}
...
...
@@ -70,7 +81,8 @@ class PDFAnnot extends PDFObject {
/// @param b Bottom coordinate
/// @param r Right coordinate
/// @param t Top coordinate
factory
PDFAnnot
.
annotation
(
PDFPage
pdfPage
,
String
s
,
double
l
,
double
b
,
double
r
,
double
t
)
=>
factory
PDFAnnot
.
annotation
(
PDFPage
pdfPage
,
String
s
,
double
l
,
double
b
,
double
r
,
double
t
)
=>
new
PDFAnnot
(
pdfPage
,
type:
"/Annot"
,
s:
s
,
l:
l
,
b:
b
,
r:
r
,
t:
t
);
/// Creates a text annotation
...
...
@@ -94,9 +106,14 @@ class PDFAnnot extends PDFObject {
/// @param ft Top coordinate
/// <br><br>Rectangle describing what part of the page to be displayed
/// (must be in User Coordinates)
factory
PDFAnnot
.
link
(
PDFPage
pdfPage
,
double
l
,
double
b
,
double
r
,
double
t
,
PDFObject
dest
,
[
double
fl
=
FULL_PAGE
,
double
fb
=
FULL_PAGE
,
double
fr
=
FULL_PAGE
,
double
ft
=
FULL_PAGE
])
=>
new
PDFAnnot
(
pdfPage
,
type:
"/Link"
,
l:
l
,
b:
b
,
r:
r
,
t:
t
,
dest:
dest
,
fl:
fl
,
fb:
fb
,
fr:
fr
,
ft:
ft
);
factory
PDFAnnot
.
link
(
PDFPage
pdfPage
,
double
l
,
double
b
,
double
r
,
double
t
,
PDFObject
dest
,
[
double
fl
=
FULL_PAGE
,
double
fb
=
FULL_PAGE
,
double
fr
=
FULL_PAGE
,
double
ft
=
FULL_PAGE
])
=>
new
PDFAnnot
(
pdfPage
,
type:
"/Link"
,
l:
l
,
b:
b
,
r:
r
,
t:
t
,
dest:
dest
,
fl:
fl
,
fb:
fb
,
fr:
fr
,
ft:
ft
);
/// Sets the border for the annotation. By default, no border is defined.
///
...
...
lib/src/border.dart
View file @
5036ac1
...
...
@@ -36,7 +36,8 @@ class PDFBorder extends PDFObject {
/// @param style The style of the border
/// @param dash The line pattern definition
/// @see PDFAnnot
PDFBorder
(
PDFDocument
pdfDocument
,
this
.
width
,
{
this
.
style
=
0
,
this
.
dash
})
:
super
(
pdfDocument
);
PDFBorder
(
PDFDocument
pdfDocument
,
this
.
width
,
{
this
.
style
=
0
,
this
.
dash
})
:
super
(
pdfDocument
);
/// @param os OutputStream to send the object to
@override
...
...
lib/src/catalog.dart
View file @
5036ac1
...
...
@@ -34,7 +34,8 @@ class PDFCatalog extends PDFObject {
/// of the documents page tree
/// @param pagemode How the document should appear when opened.
/// Allowed values are USENONE, USEOUTLINES, USETHUMBS or FULLSCREEN.
PDFCatalog
(
PDFDocument
pdfDocument
,
this
.
pdfPageList
,
this
.
pageMode
)
:
super
(
pdfDocument
,
"/Catalog"
);
PDFCatalog
(
PDFDocument
pdfDocument
,
this
.
pdfPageList
,
this
.
pageMode
)
:
super
(
pdfDocument
,
"/Catalog"
);
/// @param os OutputStream to send the object to
@override
...
...
lib/src/color.dart
View file @
5036ac1
...
...
@@ -29,8 +29,8 @@ class PDFColor {
PDFColor
(
this
.
r
,
this
.
g
,
this
.
b
,
[
this
.
a
=
1.0
]);
factory
PDFColor
.
fromInt
(
int
color
)
{
return
new
PDFColor
(
(
color
>>
16
&
0xff
)
/
255.0
,
(
color
>>
8
&
0xff
)
/
255.0
,
(
color
&
0xff
)
/
255.0
,
(
color
>>
24
&
0xff
)
/
255.0
);
return
new
PDFColor
((
color
>>
16
&
0xff
)
/
255.0
,
(
color
>>
8
&
0xff
)
/
255.0
,
(
color
&
0xff
)
/
255.0
,
(
color
>>
24
&
0xff
)
/
255.0
);
}
factory
PDFColor
.
fromHex
(
String
color
)
{
...
...
@@ -43,8 +43,8 @@ class PDFColor {
int
toInt
()
=>
((((
a
*
255.0
).
round
()
&
0xff
)
<<
24
)
|
(((
r
*
255.0
).
round
()
&
0xff
)
<<
16
)
|
(((
g
*
255.0
).
round
()
&
0xff
)
<<
8
)
|
(((
b
*
255.0
).
round
()
&
0xff
)
<<
0
))
&
(((
r
*
255.0
).
round
()
&
0xff
)
<<
16
)
|
(((
g
*
255.0
).
round
()
&
0xff
)
<<
8
)
|
(((
b
*
255.0
).
round
()
&
0xff
)
<<
0
))
&
0xFFFFFFFF
;
}
...
...
lib/src/document.dart
View file @
5036ac1
...
...
@@ -72,7 +72,12 @@ class PDFDocument {
/// <p>
/// These map the page modes just defined to the pagemodes setting of PDF.
/// </p>
static
const
_PDF_PAGE_MODES
=
const
[
"/UseNone"
,
"/UseOutlines"
,
"/UseThumbs"
,
"/FullScreen"
];
static
const
_PDF_PAGE_MODES
=
const
[
"/UseNone"
,
"/UseOutlines"
,
"/UseThumbs"
,
"/FullScreen"
];
/// This holds the current fonts
final
Set
<
PDFFont
>
fonts
=
new
Set
<
PDFFont
>();
...
...
lib/src/font.dart
View file @
5036ac1
...
...
@@ -32,7 +32,8 @@ class PDFFont extends PDFObject {
/// @param type The pdf type, ie /Type1
/// @param font The font name, ie Helvetica
/// @param style The java.awt.Font style, ie: Font.PLAIN
PDFFont
(
PDFDocument
pdfDocument
,
{
this
.
subtype
=
"/Type1"
,
this
.
baseFont
=
"/Helvetica"
})
:
super
(
pdfDocument
,
"/Font"
)
{
PDFFont
(
PDFDocument
pdfDocument
,
{
this
.
subtype
=
"/Type1"
,
this
.
baseFont
=
"/Helvetica"
})
:
super
(
pdfDocument
,
"/Font"
)
{
pdfDocument
.
fonts
.
add
(
this
);
}
...
...
lib/src/font_descriptor.dart
View file @
5036ac1
...
...
@@ -23,7 +23,8 @@ class PDFFontDescriptor extends PDFObject {
final
TtfFont
font
;
final
PDFTTFFont
ttfFont
;
PDFFontDescriptor
(
this
.
ttfFont
,
this
.
file
,
this
.
font
)
:
super
(
ttfFont
.
pdfDocument
,
"/FontDescriptor"
);
PDFFontDescriptor
(
this
.
ttfFont
,
this
.
file
,
this
.
font
)
:
super
(
ttfFont
.
pdfDocument
,
"/FontDescriptor"
);
@override
void
prepare
()
{
...
...
@@ -32,7 +33,8 @@ class PDFFontDescriptor extends PDFObject {
params
[
"/FontName"
]
=
PDFStream
.
string
(
ttfFont
.
baseFont
);
params
[
"/FontFile2"
]
=
file
.
ref
();
params
[
"/Flags"
]
=
PDFStream
.
intNum
(
32
);
params
[
"/FontBBox"
]
=
new
PDFStream
()..
putStringArray
([
font
.
head
.
xMin
,
font
.
head
.
yMin
,
font
.
head
.
xMax
,
font
.
head
.
yMax
]);
params
[
"/FontBBox"
]
=
new
PDFStream
()
..
putStringArray
([
font
.
head
.
xMin
,
font
.
head
.
yMin
,
font
.
head
.
xMax
,
font
.
head
.
yMax
]);
params
[
"/Ascent"
]
=
PDFStream
.
intNum
(
font
.
hhea
.
ascent
);
params
[
"/Descent"
]
=
PDFStream
.
intNum
(
font
.
hhea
.
descent
);
params
[
"/ItalicAngle"
]
=
PDFStream
.
intNum
(
0
);
...
...
lib/src/formxobject.dart
View file @
5036ac1
...
...
@@ -33,7 +33,8 @@ class PDFFormXObject extends PDFXObject {
/// set matrix
void
setMatrix
(
Matrix4
t
)
{
var
s
=
t
.
storage
;
params
[
"/Matrix"
]
=
PDFStream
.
string
(
"[
${s[0]}
${s[1]}
${s[4]}
${s[5]}
${s[12]}
${s[13]}
]"
);
params
[
"/Matrix"
]
=
PDFStream
.
string
(
"[
${s[0]}
${s[1]}
${s[4]}
${s[5]}
${s[12]}
${s[13]}
]"
);
}
@override
...
...
lib/src/graphics.dart
View file @
5036ac1
...
...
@@ -174,8 +174,7 @@ class PDFGraphics {
///
/// @param c Color to use
void
setColor
(
PDFColor
color
)
{
buf
.
putString
(
"
${color.r}
${color.g}
${color.b}
rg
${color.r}
${color.g}
${color
.b}
RG
\n
"
);
buf
.
putString
(
"
${color.r}
${color.g}
${color.b}
rg
${color.r}
${color.g}
${color.b}
RG
\n
"
);
}
/// Set the transformation Matrix
...
...
lib/src/info.dart
View file @
5036ac1
...
...
@@ -26,7 +26,8 @@ class PDFInfo extends PDFObject {
String
keywords
;
/// @param title Title of this document
PDFInfo
(
PDFDocument
pdfDocument
,
{
this
.
title
,
this
.
author
,
this
.
creator
,
this
.
subject
,
this
.
keywords
})
PDFInfo
(
PDFDocument
pdfDocument
,
{
this
.
title
,
this
.
author
,
this
.
creator
,
this
.
subject
,
this
.
keywords
})
:
super
(
pdfDocument
,
null
)
{
params
[
"/Producer"
]
=
PDFStream
.
text
(
"dpdf - David PHAM-VAN"
);
}
...
...
lib/src/outline.dart
View file @
5036ac1
...
...
@@ -76,7 +76,8 @@ class PDFOutline extends PDFObject {
PDFOutline
add
({
String
title
,
PDFPage
dest
,
double
x
,
y
,
w
,
h
})
{
var
xy1
=
dest
.
cxy
(
x
,
y
+
h
);
var
xy2
=
dest
.
cxy
(
x
+
w
,
y
);
PDFOutline
outline
=
new
PDFOutline
(
pdfDocument
,
title:
title
,
dest:
dest
,
l:
xy1
.
w
,
b:
xy1
.
h
,
r:
xy2
.
w
,
t:
xy2
.
h
);
PDFOutline
outline
=
new
PDFOutline
(
pdfDocument
,
title:
title
,
dest:
dest
,
l:
xy1
.
w
,
b:
xy1
.
h
,
r:
xy2
.
w
,
t:
xy2
.
h
);
// Tell the outline of ourselves
outline
.
parent
=
this
;
return
outline
;
...
...
lib/src/page.dart
View file @
5036ac1
...
...
@@ -48,7 +48,8 @@ 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
,
{
int
orientation
,
this
.
pageFormat
})
:
super
(
pdfDocument
,
"/Page"
)
{
pdfDocument
.
pdfPageList
.
pages
.
add
(
this
);
if
(
pageFormat
==
null
)
pageFormat
=
new
PDFPageFormat
();
setOrientation
(
orientation
);
...
...
@@ -132,12 +133,16 @@ class PDFPage extends PDFObject {
/// @param vh Height of the view area
/// @return Returns the annotation, so other settings can be changed.
PDFAnnot
addLink
(
double
x
,
y
,
w
,
h
,
PDFObject
dest
,
[
double
vx
=
PDFAnnot
.
FULL_PAGE
,
vy
=
PDFAnnot
.
FULL_PAGE
,
vw
=
PDFAnnot
.
FULL_PAGE
,
vh
=
PDFAnnot
.
FULL_PAGE
])
{
[
double
vx
=
PDFAnnot
.
FULL_PAGE
,
vy
=
PDFAnnot
.
FULL_PAGE
,
vw
=
PDFAnnot
.
FULL_PAGE
,
vh
=
PDFAnnot
.
FULL_PAGE
])
{
var
xy1
=
cxy
(
x
,
y
+
h
);
var
xy2
=
cxy
(
x
+
w
,
y
);
var
xy3
=
cxy
(
vx
,
vy
+
vh
);
var
xy4
=
cxy
(
vx
+
vw
,
vy
);
PDFAnnot
ob
=
new
PDFAnnot
.
link
(
this
,
xy1
.
w
,
xy1
.
h
,
xy2
.
w
,
xy2
.
h
,
dest
,
xy3
.
w
,
xy3
.
h
,
xy4
.
w
,
xy4
.
h
);
PDFAnnot
ob
=
new
PDFAnnot
.
link
(
this
,
xy1
.
w
,
xy1
.
h
,
xy2
.
w
,
xy2
.
h
,
dest
,
xy3
.
w
,
xy3
.
h
,
xy4
.
w
,
xy4
.
h
);
return
ob
;
}
...
...
@@ -152,7 +157,8 @@ class PDFPage extends PDFObject {
PDFOutline
addOutline
(
String
title
,
{
double
x
,
double
y
,
double
w
,
double
h
})
{
PDFPoint
xy1
=
cxy
(
x
,
y
+
h
);
PDFPoint
xy2
=
cxy
(
x
+
w
,
y
);
PDFOutline
outline
=
new
PDFOutline
(
pdfDocument
,
title:
title
,
dest:
this
,
l:
xy1
.
w
,
b:
xy1
.
h
,
r:
xy2
.
w
,
t:
xy2
.
h
);
PDFOutline
outline
=
new
PDFOutline
(
pdfDocument
,
title:
title
,
dest:
this
,
l:
xy1
.
w
,
b:
xy1
.
h
,
r:
xy2
.
w
,
t:
xy2
.
h
);
pdfDocument
.
outline
.
outlines
.
add
(
outline
);
return
outline
;
}
...
...
@@ -166,7 +172,8 @@ class PDFPage extends PDFObject {
params
[
"/Parent"
]
=
pdfDocument
.
pdfPageList
.
ref
();
// the /MediaBox for the page size
params
[
"/MediaBox"
]
=
new
PDFStream
()..
putStringArray
([
0
,
0
,
pageFormat
.
getWidth
(),
pageFormat
.
getHeight
()]);
params
[
"/MediaBox"
]
=
new
PDFStream
()
..
putStringArray
([
0
,
0
,
pageFormat
.
getWidth
(),
pageFormat
.
getHeight
()]);
// Rotation (if not zero)
// if(rotate!=0) {
...
...
lib/src/stream.dart
View file @
5036ac1
...
...
@@ -119,7 +119,8 @@ class PDFStream {
putString
(
">>"
);
}
static
PDFStream
dictionary
(
Map
<
String
,
PDFStream
>
values
)
=>
new
PDFStream
()..
putDictionary
(
values
);
static
PDFStream
dictionary
(
Map
<
String
,
PDFStream
>
values
)
=>
new
PDFStream
()..
putDictionary
(
values
);
void
putObjectDictionary
(
Map
<
String
,
PDFObject
>
values
)
{
putString
(
"<< "
);
...
...
lib/src/ttffont.dart
View file @
5036ac1
...
...
@@ -28,7 +28,8 @@ class PDFTTFFont extends PDFFont {
int
_charMax
;
/// Constructs a PDFTTFFont
PDFTTFFont
(
PDFDocument
pdfDocument
,
Uint8List
bytes
)
:
super
(
pdfDocument
,
subtype:
"/TrueType"
)
{
PDFTTFFont
(
PDFDocument
pdfDocument
,
Uint8List
bytes
)
:
super
(
pdfDocument
,
subtype:
"/TrueType"
)
{
_font
=
new
TtfParser
().
parse
(
bytes
);
baseFont
=
"/"
+
_font
.
name
.
fontName
.
replaceAll
(
" "
,
""
);
...
...
lib/src/xref.dart
View file @
5036ac1
...
...
@@ -36,7 +36,8 @@ class PDFXref {
/// @return The xref in the format of the xref section in the PDF file
String
ref
()
{
String
rs
=
offset
.
toString
().
padLeft
(
10
,
'0'
)
+
" "
+
generation
.
toString
().
padLeft
(
5
,
'0'
);
String
rs
=
offset
.
toString
().
padLeft
(
10
,
'0'
)
+
" "
+
generation
.
toString
().
padLeft
(
5
,
'0'
);
if
(
generation
==
65535
)
return
rs
+
" f "
;
return
rs
+
" n "
;
...
...
Please
register
or
login
to post a comment