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
2021-04-05 09:00:38 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
85e5c972ccea0a4c7ffcb44af75b5351e172cea4
85e5c972
1 parent
ebc78a8a
Add support for Metadata XML
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
98 additions
and
10 deletions
pdf/CHANGELOG.md
pdf/lib/pdf.dart
pdf/lib/src/pdf/catalog.dart
pdf/lib/src/pdf/data_types.dart
pdf/lib/src/pdf/document.dart
pdf/lib/src/pdf/metadata.dart
pdf/lib/src/pdf/object_stream.dart
pdf/lib/src/pdf/output.dart
pdf/lib/src/widgets/document.dart
pdf/test/complex_test.dart
pdf/CHANGELOG.md
View file @
85e5c97
...
...
@@ -7,6 +7,7 @@
-
Improve GraphicState
-
Add SVG Color filter
-
Implement Compressed XREF
-
Add support for Metadata XML
## 3.1.0
...
...
pdf/lib/pdf.dart
View file @
85e5c97
...
...
@@ -30,6 +30,7 @@ export 'src/pdf/graphic_state.dart';
export
'src/pdf/graphics.dart'
;
export
'src/pdf/image.dart'
;
export
'src/pdf/info.dart'
;
export
'src/pdf/metadata.dart'
;
export
'src/pdf/outline.dart'
;
export
'src/pdf/page.dart'
;
export
'src/pdf/page_format.dart'
;
...
...
pdf/lib/src/pdf/catalog.dart
View file @
85e5c97
...
...
@@ -17,6 +17,7 @@
import
'annotation.dart'
;
import
'data_types.dart'
;
import
'document.dart'
;
import
'metadata.dart'
;
import
'names.dart'
;
import
'object_dict.dart'
;
import
'outline.dart'
;
...
...
@@ -38,6 +39,9 @@ class PdfCatalog extends PdfObjectDict {
/// The outlines of the document
PdfOutline
?
outlines
;
/// The document metadata
PdfMetadata
?
metadata
;
/// The initial page mode
final
PdfPageMode
pageMode
;
...
...
@@ -66,6 +70,10 @@ class PdfCatalog extends PdfObjectDict {
params
[
'/Outlines'
]
=
outlines
!.
ref
();
}
if
(
metadata
!=
null
)
{
params
[
'/Metadata'
]
=
metadata
!.
ref
();
}
// the Names object
params
[
'/Names'
]
=
names
.
ref
();
...
...
pdf/lib/src/pdf/data_types.dart
View file @
85e5c97
...
...
@@ -595,15 +595,34 @@ class PdfDict<T extends PdfDataType> extends PdfDataType {
}
class
PdfDictStream
extends
PdfDict
<
PdfDataType
>
{
const
PdfDictStream
({
factory
PdfDictStream
({
required
PdfObject
object
,
Map
<
String
,
PdfDataType
>?
values
,
Uint8List
?
data
,
bool
isBinary
=
false
,
bool
encrypt
=
true
,
bool
compress
=
true
,
})
{
return
PdfDictStream
.
values
(
object:
object
,
values:
values
??
{},
data:
data
??
Uint8List
(
0
),
encrypt:
encrypt
,
compress:
compress
,
isBinary:
isBinary
,
);
}
PdfDictStream
.
values
({
required
this
.
object
,
Map
<
String
,
PdfDataType
>
values
=
const
<
String
,
PdfDataType
>{}
,
required
Map
<
String
,
PdfDataType
>
values
,
required
this
.
data
,
this
.
isBinary
=
false
,
this
.
encrypt
=
true
,
this
.
compress
=
true
,
})
:
super
.
values
(
values
);
final
Uint8List
data
;
Uint8List
data
;
final
PdfObject
object
;
...
...
@@ -611,6 +630,8 @@ class PdfDictStream extends PdfDict<PdfDataType> {
final
bool
encrypt
;
final
bool
compress
;
@override
void
output
(
PdfStream
s
)
{
final
_values
=
PdfDict
(
values
);
...
...
@@ -620,7 +641,7 @@ class PdfDictStream extends PdfDict<PdfDataType> {
if
(
_values
.
containsKey
(
'/Filter'
))
{
// The data is already in the right format
_data
=
data
;
}
else
if
(
object
.
pdfDocument
.
deflate
!=
null
)
{
}
else
if
(
compress
&&
object
.
pdfDocument
.
deflate
!=
null
)
{
// Compress the data
final
newData
=
Uint8List
.
fromList
(
object
.
pdfDocument
.
deflate
!(
data
));
if
(
newData
.
lengthInBytes
<
data
.
lengthInBytes
)
{
...
...
pdf/lib/src/pdf/document.dart
View file @
85e5c97
...
...
@@ -123,6 +123,7 @@ class PdfDocument {
/// This is the info object. Although this is an optional object, we
/// include it.
@Deprecated
(
'This can safely be removed.'
)
PdfInfo
?
info
;
/// This is the Pages object, which is required by each Pdf Document
...
...
pdf/lib/src/pdf/metadata.dart
0 → 100644
View file @
85e5c97
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'package:xml/xml.dart'
;
import
'data_types.dart'
;
import
'document.dart'
;
import
'object.dart'
;
/// Pdf Metadata
class
PdfMetadata
extends
PdfObject
<
PdfDictStream
>
{
/// Store an Xml object
PdfMetadata
(
PdfDocument
pdfDocument
,
this
.
metadata
,
)
:
super
(
pdfDocument
,
params:
PdfDictStream
(
object:
pdfDocument
.
catalog
,
compress:
false
,
encrypt:
false
,
),
)
{
pdfDocument
.
catalog
.
metadata
=
this
;
}
final
XmlDocument
metadata
;
@override
void
prepare
()
{
super
.
prepare
();
params
[
'/SubType'
]
=
const
PdfName
(
'/XML'
);
params
.
data
=
Uint8List
.
fromList
(
utf8
.
encode
(
metadata
.
toString
()));
}
}
...
...
pdf/lib/src/pdf/object_stream.dart
View file @
85e5c97
...
...
@@ -36,7 +36,7 @@ class PdfObjectStream extends PdfObjectDict {
@override
void
writeContent
(
PdfStream
os
)
{
PdfDictStream
(
PdfDictStream
.
values
(
object:
this
,
isBinary:
isBinary
,
values:
params
.
values
,
...
...
pdf/lib/src/pdf/output.dart
View file @
85e5c97
...
...
@@ -52,10 +52,10 @@ class PdfOutput {
final
xref
=
PdfXrefTable
();
/// This is used to track the /Root object (catalog)
Pdf
Object
?
rootID
;
Pdf
Catalog
?
rootID
;
/// This is used to track the /Info object (info)
Pdf
Object
?
infoID
;
Pdf
Info
?
infoID
;
/// This is used to track the /Encrypt object (encryption)
PdfEncryption
?
encryptID
;
...
...
pdf/lib/src/widgets/document.dart
View file @
85e5c97
...
...
@@ -17,6 +17,7 @@
import
'dart:typed_data'
;
import
'package:pdf/pdf.dart'
;
import
'package:xml/xml.dart'
;
import
'page.dart'
;
import
'theme.dart'
;
...
...
@@ -34,6 +35,7 @@ class Document {
String
?
subject
,
String
?
keywords
,
String
?
producer
,
XmlDocument
?
metadata
,
})
:
document
=
PdfDocument
(
pageMode:
pageMode
,
deflate:
deflate
,
...
...
@@ -46,7 +48,7 @@ class Document {
subject
!=
null
||
keywords
!=
null
||
producer
!=
null
)
{
document
.
info
=
PdfInfo
(
PdfInfo
(
document
,
title:
title
,
author:
author
,
...
...
@@ -56,6 +58,9 @@ class Document {
producer:
producer
,
);
}
if
(
metadata
!=
null
)
{
PdfMetadata
(
document
,
metadata
);
}
}
Document
.
load
(
...
...
@@ -82,7 +87,7 @@ class Document {
subject
!=
null
||
keywords
!=
null
||
producer
!=
null
)
{
document
.
info
=
PdfInfo
(
PdfInfo
(
document
,
title:
title
,
author:
author
,
...
...
pdf/test/complex_test.dart
View file @
85e5c97
...
...
@@ -28,7 +28,7 @@ void main() {
img
.
fillRange
(
0
,
img
.
length
-
1
,
0x12345678
);
final
pdf
=
PdfDocument
();
pdf
.
info
=
PdfInfo
(
pdf
,
PdfInfo
(
pdf
,
author:
'David PHAM-VAN'
,
creator:
'David PHAM-VAN'
,
title:
'My Title'
,
...
...
Please
register
or
login
to post a comment