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
2022-02-23 07:47:56 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2bb8a6309ec3ae3afb9ffeab1e8ab506385a523e
2bb8a630
1 parent
d1803a2f
Improve debugging information
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
30 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/obj/diagnostic.dart
pdf/lib/src/pdf/obj/image.dart
pdf/lib/src/pdf/obj/object.dart
pdf/lib/src/pdf/output.dart
pdf/pubspec.yaml
pdf/CHANGELOG.md
View file @
2bb8a63
# Changelog
## 3.7.2
-
Improve debugging information
## 3.7.1
-
Fix missing chars with pdfjs
...
...
pdf/lib/src/pdf/obj/diagnostic.dart
0 → 100644
View file @
2bb8a63
import
'dart:math'
as
math
;
import
'package:meta/meta.dart'
;
import
'../stream.dart'
;
mixin
PdfDiagnostic
{
static
const
_maxSize
=
300
;
final
_properties
=
<
String
>[];
int
?
_offset
;
Stopwatch
?
_stopwatch
;
int
get
elapsedStopwatch
=>
_stopwatch
?.
elapsedMicroseconds
??
0
;
@protected
@mustCallSuper
void
debugFill
(
String
value
)
{
assert
(()
{
if
(
_properties
.
isEmpty
)
{
_properties
.
add
(
''
);
_properties
.
add
(
'-'
*
78
);
_properties
.
add
(
'
$runtimeType
'
);
}
_properties
.
add
(
value
);
return
true
;
}());
}
void
setInsertion
(
PdfStream
os
)
{
assert
(()
{
_offset
=
os
.
offset
;
os
.
putComment
(
' '
*
_maxSize
);
return
true
;
}());
}
void
writeDebug
(
PdfStream
os
)
{
assert
(()
{
if
(
_offset
!=
null
)
{
final
o
=
PdfStream
();
_properties
.
forEach
(
o
.
putComment
);
_properties
.
forEach
(
print
);
final
b
=
o
.
output
();
os
.
setBytes
(
_offset
!,
b
.
sublist
(
0
,
math
.
min
(
_maxSize
+
2
,
b
.
lengthInBytes
-
1
)),
);
}
return
true
;
}());
}
void
startStopwatch
()
{
_stopwatch
??=
Stopwatch
();
_stopwatch
!.
start
();
}
void
stopStopwatch
()
{
_stopwatch
?.
stop
();
}
}
...
...
pdf/lib/src/pdf/obj/image.dart
View file @
2bb8a63
...
...
@@ -69,6 +69,12 @@ class PdfImage extends PdfXObject {
orientation
,
);
assert
(()
{
im
.
startStopwatch
();
im
.
debugFill
(
'RAW RGB
${alpha ? 'A' : ''}
Image
${width}
x
$height
'
);
return
true
;
}());
im
.
params
[
'/BitsPerComponent'
]
=
const
PdfNum
(
8
);
im
.
params
[
'/Name'
]
=
PdfName
(
im
.
name
);
im
.
params
[
'/ColorSpace'
]
=
const
PdfName
(
'/DeviceRGB'
);
...
...
@@ -95,6 +101,10 @@ class PdfImage extends PdfXObject {
}
im
.
buf
.
putBytes
(
out
);
assert
(()
{
im
.
stopStopwatch
();
return
true
;
}());
return
im
;
}
...
...
@@ -112,6 +122,11 @@ class PdfImage extends PdfXObject {
orientation
??
info
.
orientation
,
);
assert
(()
{
im
.
startStopwatch
();
im
.
debugFill
(
'Jpeg Image
${info.width}
x
${info.height}
'
);
return
true
;
}());
im
.
params
[
'/BitsPerComponent'
]
=
const
PdfNum
(
8
);
im
.
params
[
'/Name'
]
=
PdfName
(
im
.
name
);
im
.
params
[
'/Intent'
]
=
const
PdfName
(
'/RelativeColorimetric'
);
...
...
@@ -124,6 +139,10 @@ class PdfImage extends PdfXObject {
}
im
.
buf
.
putBytes
(
image
);
assert
(()
{
im
.
stopStopwatch
();
return
true
;
}());
return
im
;
}
...
...
@@ -178,6 +197,11 @@ class PdfImage extends PdfXObject {
orientation
,
);
assert
(()
{
im
.
startStopwatch
();
im
.
debugFill
(
'Image alpha channel
${width}
x
$height
'
);
return
true
;
}());
im
.
params
[
'/BitsPerComponent'
]
=
const
PdfNum
(
8
);
im
.
params
[
'/Name'
]
=
PdfName
(
im
.
name
);
im
.
params
[
'/ColorSpace'
]
=
const
PdfName
(
'/DeviceGray'
);
...
...
@@ -193,6 +217,10 @@ class PdfImage extends PdfXObject {
}
im
.
buf
.
putBytes
(
out
);
assert
(()
{
im
.
stopStopwatch
();
return
true
;
}());
return
im
;
}
...
...
@@ -204,6 +232,10 @@ class PdfImage extends PdfXObject {
)
:
super
(
pdfDocument
,
'/Image'
,
isBinary:
true
)
{
params
[
'/Width'
]
=
PdfNum
(
_width
);
params
[
'/Height'
]
=
PdfNum
(
_height
);
assert
(()
{
debugFill
(
'Orientation:
$orientation
'
);
return
true
;
}());
}
final
int
_width
;
...
...
pdf/lib/src/pdf/obj/object.dart
View file @
2bb8a63
...
...
@@ -19,9 +19,10 @@ import 'package:meta/meta.dart';
import
'../data_types.dart'
;
import
'../document.dart'
;
import
'../stream.dart'
;
import
'diagnostic.dart'
;
/// Base Object used in the PDF file
abstract
class
PdfObject
<
T
extends
PdfDataType
>
{
abstract
class
PdfObject
<
T
extends
PdfDataType
>
with
PdfDiagnostic
{
/// This is usually called by extensors to this class, and sets the
/// Pdf Object Type
PdfObject
(
...
...
@@ -60,15 +61,6 @@ abstract class PdfObject<T extends PdfDataType> {
/// The write method should call this before writing anything to the
/// OutputStream. This will send the standard header for each object.
void
_writeStart
(
PdfStream
os
)
{
assert
(()
{
if
(
pdfDocument
.
verbose
)
{
os
.
putComment
(
''
);
os
.
putComment
(
'-'
*
78
);
os
.
putComment
(
'
$runtimeType
'
);
}
return
true
;
}());
os
.
putString
(
'
$objser
$objgen
obj
\n
'
);
}
...
...
pdf/lib/src/pdf/output.dart
View file @
2bb8a63
...
...
@@ -17,6 +17,7 @@
import
'data_types.dart'
;
import
'document.dart'
;
import
'obj/catalog.dart'
;
import
'obj/diagnostic.dart'
;
import
'obj/encryption.dart'
;
import
'obj/info.dart'
;
import
'obj/object.dart'
;
...
...
@@ -25,7 +26,7 @@ import 'stream.dart';
import
'xref.dart'
;
/// PDF document writer
class
PdfOutput
{
class
PdfOutput
with
PdfDiagnostic
{
/// This creates a Pdf [PdfStream]
PdfOutput
(
this
.
os
,
this
.
version
,
this
.
verbose
)
{
String
v
;
...
...
@@ -42,20 +43,16 @@ class PdfOutput {
os
.
putBytes
(
const
<
int
>[
0x25
,
0xC2
,
0xA5
,
0xC2
,
0xB1
,
0xC3
,
0xAB
,
0x0A
]);
assert
(()
{
if
(
verbose
)
{
_stopwatch
=
Stopwatch
()..
start
();
os
.
putComment
(
''
);
os
.
putComment
(
'Verbose dart_pdf'
);
os
.
putComment
(
'Creation date:
${DateTime.now()}
'
);
_comment
=
os
.
offset
;
os
.
putBytes
(
List
<
int
>.
filled
(
120
,
0x20
));
setInsertion
(
os
);
startStopwatch
();
debugFill
(
'Verbose dart_pdf'
);
debugFill
(
'Producer https://github.com/DavBfr/dart_pdf'
);
debugFill
(
'Creation date:
${DateTime.now()}
'
);
}
return
true
;
}());
}
late
final
Stopwatch
_stopwatch
;
var
_comment
=
0
;
/// Pdf version to output
final
PdfVersion
version
;
...
...
@@ -98,7 +95,23 @@ class PdfOutput {
}
xref
.
add
(
PdfXref
(
ob
.
objser
,
os
.
offset
));
assert
(()
{
if
(
verbose
)
{
ob
.
setInsertion
(
os
);
ob
.
startStopwatch
();
}
return
true
;
}());
ob
.
write
(
os
);
assert
(()
{
if
(
verbose
)
{
ob
.
stopStopwatch
();
ob
.
debugFill
(
'Creation time:
${ob.elapsedStopwatch / Duration.microsecondsPerSecond}
seconds'
);
ob
.
writeDebug
(
os
);
}
return
true
;
}());
}
/// This closes the Stream, writing the xref table
...
...
@@ -171,15 +184,13 @@ class PdfOutput {
assert
(()
{
if
(
verbose
)
{
_stopwatch
.
stop
();
final
h
=
PdfStream
();
h
.
putComment
(
'Creation time:
${_stopwatch.elapsed.inMicroseconds / Duration.microsecondsPerSecond}
seconds'
);
h
.
putComment
(
'File size:
${os.offset}
bytes'
);
h
.
putComment
(
'Pages:
${rootID!.pdfDocument.pdfPageList.pages.length}
'
);
h
.
putComment
(
'Objects:
${xref.offsets.length}
'
);
os
.
setBytes
(
_comment
,
h
.
output
());
stopStopwatch
();
debugFill
(
'Creation time:
${elapsedStopwatch / Duration.microsecondsPerSecond}
seconds'
);
debugFill
(
'File size:
${os.offset}
bytes'
);
debugFill
(
'Pages:
${rootID!.pdfDocument.pdfPageList.pages.length}
'
);
debugFill
(
'Objects:
${xref.offsets.length}
'
);
writeDebug
(
os
);
}
return
true
;
}());
...
...
pdf/pubspec.yaml
View file @
2bb8a63
...
...
@@ -3,7 +3,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.7.
1
version
:
3.7.
2
environment
:
sdk
:
"
>=2.12.0
<3.0.0"
...
...
Please
register
or
login
to post a comment