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
2023-03-18 11:15:17 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
62427125fadf8570f52ae513a4175603450a385d
62427125
1 parent
7f83264c
Improve PdfObjectBase
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
52 deletions
pdf/lib/src/pdf/format/object_base.dart
pdf/lib/src/pdf/format/xref.dart
pdf/lib/src/pdf/obj/signature.dart
pdf/test/minimal_test.dart
pdf/lib/src/pdf/format/object_base.dart
View file @
6242712
...
...
@@ -42,6 +42,10 @@ class PdfObjectBase<T extends PdfDataType> with PdfDiagnostic {
required
this
.
objser
,
this
.
objgen
=
0
,
required
this
.
params
,
this
.
deflate
,
this
.
encryptCallback
,
this
.
verbose
=
false
,
this
.
version
=
PdfVersion
.
pdf_1_5
,
});
/// This is the unique serial number for this object.
...
...
@@ -53,23 +57,44 @@ class PdfObjectBase<T extends PdfDataType> with PdfDiagnostic {
final
T
params
;
/// Callback used to compress the data
DeflateCallback
?
get
deflate
=>
null
;
final
DeflateCallback
?
deflate
;
/// Callback used to encrypt the value of a [PdfDictStream] or a [PdfEncStream]
PdfEncryptCallback
?
get
encryptCallback
=>
null
;
final
PdfEncryptCallback
?
encryptCallback
;
/// Output a PDF document with comments and formatted data
bool
get
verbose
=>
fal
se
;
final
bool
verbo
se
;
PdfVersion
get
version
=>
PdfVersion
.
pdf_1_5
;
/// PDF version to generate
final
PdfVersion
version
;
/// Returns the unique serial number in Pdf format
PdfIndirect
ref
()
=>
PdfIndirect
(
objser
,
objgen
);
void
output
(
PdfStream
s
)
{
int
output
(
PdfStream
s
)
{
assert
(()
{
if
(
verbose
)
{
setInsertion
(
s
,
160
);
startStopwatch
();
}
return
true
;
}());
final
offset
=
s
.
offset
;
s
.
putString
(
'
$objser
$objgen
obj
\n
'
);
writeContent
(
s
);
s
.
putString
(
'endobj
\n
'
);
assert
(()
{
if
(
verbose
)
{
stopStopwatch
();
debugFill
(
'Creation time:
${elapsedStopwatch / Duration.microsecondsPerSecond}
seconds'
);
writeDebug
(
s
);
}
return
true
;
}());
return
offset
;
}
void
writeContent
(
PdfStream
s
)
{
...
...
pdf/lib/src/pdf/format/xref.dart
View file @
6242712
...
...
@@ -144,24 +144,8 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic {
}());
for
(
final
ob
in
objects
)
{
assert
(()
{
if
(
ob
.
verbose
)
{
ob
.
setInsertion
(
s
,
150
);
ob
.
startStopwatch
();
}
return
true
;
}());
_offsets
.
add
(
PdfXref
(
ob
.
objser
,
s
.
offset
,
generation:
ob
.
objgen
));
ob
.
output
(
s
);
assert
(()
{
if
(
ob
.
verbose
)
{
ob
.
stopStopwatch
();
ob
.
debugFill
(
'Creation time:
${ob.elapsedStopwatch / Duration.microsecondsPerSecond}
seconds'
);
ob
.
writeDebug
(
s
);
}
return
true
;
}());
final
offset
=
ob
.
output
(
s
);
_offsets
.
add
(
PdfXref
(
ob
.
objser
,
offset
,
generation:
ob
.
objgen
));
}
final
int
xrefOffset
;
...
...
@@ -195,7 +179,6 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic {
debugFill
(
'Creation time:
${elapsedStopwatch / Duration.microsecondsPerSecond}
seconds'
);
debugFill
(
'File size:
${s.offset}
bytes'
);
// debugFill('Pages: ${rootID!.pdfDocument.pdfPageList.pages.length}');
debugFill
(
'Objects:
${objects.length}
'
);
writeDebug
(
s
);
}
...
...
@@ -337,16 +320,19 @@ class PdfXrefTable extends PdfDataType with PdfDiagnostic {
final
objOffset
=
s
.
offset
;
s
.
putString
(
'
$id
0 obj
\n
'
);
PdfObjectBase
(
objser:
id
,
params:
PdfDictStream
(
data:
binOffsets
.
buffer
.
asUint8List
(),
isBinary:
false
,
encrypt:
false
,
values:
params
.
values
,
),
deflate:
o
.
deflate
,
verbose:
o
.
verbose
,
version:
o
.
version
,
).
output
(
s
);
PdfDictStream
(
data:
binOffsets
.
buffer
.
asUint8List
(),
isBinary:
false
,
encrypt:
false
,
values:
params
.
values
,
).
output
(
o
,
s
,
o
.
verbose
?
0
:
null
);
s
.
putString
(
'
\n
endobj
\n
'
);
return
objOffset
;
}
}
...
...
pdf/lib/src/pdf/obj/signature.dart
View file @
6242712
...
...
@@ -82,12 +82,13 @@ class PdfSignature extends PdfObjectDict {
int
?
_offsetEnd
;
@override
void
output
(
PdfStream
s
)
{
int
output
(
PdfStream
s
)
{
value
.
preSign
(
this
,
params
);
_offsetStart
=
s
.
offset
+
'
$objser
$objgen
obj
\n
'
.
length
;
super
.
output
(
s
);
final
offset
=
super
.
output
(
s
);
_offsetEnd
=
s
.
offset
;
return
offset
;
}
Future
<
void
>
writeSignature
(
PdfStream
os
)
async
{
...
...
pdf/test/minimal_test.dart
View file @
6242712
...
...
@@ -21,38 +21,33 @@ import 'package:pdf/pdf.dart';
import
'package:pdf/src/priv.dart'
;
import
'package:test/test.dart'
;
class
BasicObject
<
T
extends
PdfDataType
>
extends
PdfObjectBase
<
T
>
{
BasicObject
({
required
super
.
objser
,
required
super
.
params
});
@override
bool
get
verbose
=>
true
;
@override
PdfVersion
get
version
=>
PdfVersion
.
pdf_1_4
;
@override
DeflateCallback
?
get
deflate
=>
zlib
.
encode
;
}
void
main
(
)
{
test
(
'Pdf Minimal'
,
()
async
{
var
objser
=
1
;
const
verbose
=
true
;
const
version
=
PdfVersion
.
pdf_1_4
;
final
pages
=
BasicObject
(
final
pages
=
PdfObjectBase
(
objser:
objser
++,
verbose:
verbose
,
version:
version
,
params:
PdfDict
({
'/Type'
:
const
PdfName
(
'/Pages'
),
'/Count'
:
const
PdfNum
(
1
),
}));
final
content
=
BasicObject
(
final
content
=
PdfObjectBase
(
objser:
objser
++,
verbose:
verbose
,
version:
version
,
params:
PdfDictStream
(
data:
latin1
.
encode
(
'30 811.88976 m 200 641.88976 l S'
),
));
final
page
=
BasicObject
(
final
page
=
PdfObjectBase
(
objser:
objser
++,
verbose:
verbose
,
version:
version
,
params:
PdfDict
({
'/Type'
:
const
PdfName
(
'/Page'
),
'/Parent'
:
pages
.
ref
(),
...
...
@@ -67,8 +62,10 @@ void main() {
pages
.
params
[
'/Kids'
]
=
PdfArray
([
page
.
ref
()]);
final
catalog
=
BasicObject
(
final
catalog
=
PdfObjectBase
(
objser:
objser
++,
verbose:
verbose
,
version:
version
,
params:
PdfDict
({
'/Type'
:
const
PdfName
(
'/Catalog'
),
'/Pages'
:
pages
.
ref
(),
...
...
Please
register
or
login
to post a comment