Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
docxtemplater-image-module
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
docxtemplater-image-module
Commits
eca28cc1
Commit
eca28cc1
authored
Jul 20, 2016
by
Edgar HIPP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update checks == null
parent
ca42a850
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
23 deletions
+23
-23
es6/imgManager.js
+1
-1
es6/imgReplacer.js
+3
-3
es6/index.js
+3
-3
es6/test.js
+16
-16
No files found.
es6/imgManager.js
View file @
eca28cc1
...
@@ -31,7 +31,7 @@ module.exports = class ImgManager {
...
@@ -31,7 +31,7 @@ module.exports = class ImgManager {
}
}
loadImageRels
()
{
loadImageRels
()
{
const
file
=
this
.
zip
.
files
[
`word/_rels/
${
this
.
endFileName
}
.xml.rels`
]
||
this
.
zip
.
files
[
"word/_rels/document.xml.rels"
];
const
file
=
this
.
zip
.
files
[
`word/_rels/
${
this
.
endFileName
}
.xml.rels`
]
||
this
.
zip
.
files
[
"word/_rels/document.xml.rels"
];
if
(
file
==
=
undefined
)
{
return
;
}
if
(
file
==
null
)
{
return
;
}
const
content
=
DocUtils
.
decodeUtf8
(
file
.
asText
());
const
content
=
DocUtils
.
decodeUtf8
(
file
.
asText
());
this
.
xmlDoc
=
DocUtils
.
str2xml
(
content
);
this
.
xmlDoc
=
DocUtils
.
str2xml
(
content
);
// Get all Rids
// Get all Rids
...
...
es6/imgReplacer.js
View file @
eca28cc1
...
@@ -71,10 +71,10 @@ module.exports = class ImgReplacer {
...
@@ -71,10 +71,10 @@ module.exports = class ImgReplacer {
return
;
return
;
}
}
const
tagrId
=
xmlImg
.
getElementsByTagName
(
"a:blip"
)[
0
];
const
tagrId
=
xmlImg
.
getElementsByTagName
(
"a:blip"
)[
0
];
if
(
tagrId
==
=
undefined
)
{
throw
new
Error
(
"tagRiD undefined !"
);
}
if
(
tagrId
==
null
)
{
throw
new
Error
(
"tagRiD undefined !"
);
}
const
rId
=
tagrId
.
getAttribute
(
"r:embed"
);
const
rId
=
tagrId
.
getAttribute
(
"r:embed"
);
const
tag
=
xmlImg
.
getElementsByTagName
(
"wp:docPr"
)[
0
];
const
tag
=
xmlImg
.
getElementsByTagName
(
"wp:docPr"
)[
0
];
if
(
tag
==
=
undefined
)
{
throw
new
Error
(
"tag undefined"
);
}
if
(
tag
==
null
)
{
throw
new
Error
(
"tag undefined"
);
}
// if image is already a replacement then do nothing
// if image is already a replacement then do nothing
if
(
tag
.
getAttribute
(
"name"
).
substr
(
0
,
6
)
===
"Copie_"
)
{
return
;
}
if
(
tag
.
getAttribute
(
"name"
).
substr
(
0
,
6
)
===
"Copie_"
)
{
return
;
}
const
imgName
=
this
.
imgManager
.
getImageName
();
const
imgName
=
this
.
imgManager
.
getImageName
();
...
@@ -86,7 +86,7 @@ module.exports = class ImgReplacer {
...
@@ -86,7 +86,7 @@ module.exports = class ImgReplacer {
tag
.
setAttribute
(
"name"
,
`
${
imgName
}
`
);
tag
.
setAttribute
(
"name"
,
`
${
imgName
}
`
);
tagrId
.
setAttribute
(
"r:embed"
,
`rId
${
newId
}
`
);
tagrId
.
setAttribute
(
"r:embed"
,
`rId
${
newId
}
`
);
const
imageTag
=
xmlImg
.
getElementsByTagName
(
"w:drawing"
)[
0
];
const
imageTag
=
xmlImg
.
getElementsByTagName
(
"w:drawing"
)[
0
];
if
(
imageTag
==
=
undefined
)
{
throw
new
Error
(
"imageTag undefined"
);
}
if
(
imageTag
==
null
)
{
throw
new
Error
(
"imageTag undefined"
);
}
const
replacement
=
DocUtils
.
xml2Str
(
imageTag
);
const
replacement
=
DocUtils
.
xml2Str
(
imageTag
);
this
.
xmlTemplater
.
content
=
this
.
xmlTemplater
.
content
.
replace
(
match
[
0
],
replacement
);
this
.
xmlTemplater
.
content
=
this
.
xmlTemplater
.
content
.
replace
(
match
[
0
],
replacement
);
...
...
es6/index.js
View file @
eca28cc1
...
@@ -7,9 +7,9 @@ const ImgReplacer = require("./imgReplacer");
...
@@ -7,9 +7,9 @@ const ImgReplacer = require("./imgReplacer");
class
ImageModule
{
class
ImageModule
{
constructor
(
options
)
{
constructor
(
options
)
{
this
.
options
=
options
||
{};
this
.
options
=
options
||
{};
if
(
!
(
this
.
options
.
centered
!=
null
)
)
{
this
.
options
.
centered
=
false
;
}
if
(
this
.
options
.
centered
==
null
)
{
this
.
options
.
centered
=
false
;
}
if
(
!
(
this
.
options
.
getImage
!=
null
)
)
{
throw
new
Error
(
"You should pass getImage"
);
}
if
(
this
.
options
.
getImage
==
null
)
{
throw
new
Error
(
"You should pass getImage"
);
}
if
(
!
(
this
.
options
.
getSize
!=
null
)
)
{
throw
new
Error
(
"You should pass getSize"
);
}
if
(
this
.
options
.
getSize
==
null
)
{
throw
new
Error
(
"You should pass getSize"
);
}
this
.
qrQueue
=
[];
this
.
qrQueue
=
[];
this
.
imageNumber
=
1
;
this
.
imageNumber
=
1
;
}
}
...
...
es6/test.js
View file @
eca28cc1
...
@@ -98,16 +98,16 @@ describe("image adding with {% image} syntax", function () {
...
@@ -98,16 +98,16 @@ describe("image adding with {% image} syntax", function () {
fs
.
writeFile
(
"test7.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
fs
.
writeFile
(
"test7.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
expect
(
(
typeof
imageFile
!==
"undefined"
&&
imageFile
!==
null
)
,
"No image file found"
).
to
.
equal
(
true
);
expect
(
imageFile
!=
null
,
"No image file found"
).
to
.
equal
(
true
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
expect
(
(
typeof
relsFile
!==
"undefined"
&&
relsFile
!==
null
)
,
"No rels file found"
).
to
.
equal
(
true
);
expect
(
relsFile
!=
null
,
"No rels file found"
).
to
.
equal
(
true
);
const
relsFileContent
=
relsFile
.
asText
();
const
relsFileContent
=
relsFile
.
asText
();
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
expect
(
(
typeof
documentFile
!==
"undefined"
&&
documentFile
!==
null
)
,
"No document file found"
).
to
.
equal
(
true
);
expect
(
documentFile
!=
null
,
"No document file found"
).
to
.
equal
(
true
);
documentFile
.
asText
();
documentFile
.
asText
();
});
});
...
@@ -134,16 +134,16 @@ describe("image adding with {% image} syntax", function () {
...
@@ -134,16 +134,16 @@ describe("image adding with {% image} syntax", function () {
const
zip
=
out
.
getZip
();
const
zip
=
out
.
getZip
();
fs
.
writeFile
(
"test_center.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
fs
.
writeFile
(
"test_center.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
expect
(
(
typeof
imageFile
!==
"undefined"
&&
imageFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
imageFile
!=
null
).
to
.
equal
(
true
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
expect
(
(
typeof
relsFile
!==
"undefined"
&&
relsFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
relsFile
!=
null
).
to
.
equal
(
true
);
const
relsFileContent
=
relsFile
.
asText
();
const
relsFileContent
=
relsFile
.
asText
();
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
expect
(
(
typeof
documentFile
!==
"undefined"
&&
documentFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
documentFile
!=
null
).
to
.
equal
(
true
);
documentFile
.
asText
();
documentFile
.
asText
();
});
});
...
@@ -158,20 +158,20 @@ describe("image adding with {% image} syntax", function () {
...
@@ -158,20 +158,20 @@ describe("image adding with {% image} syntax", function () {
const
zip
=
out
.
getZip
();
const
zip
=
out
.
getZip
();
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
expect
(
(
typeof
imageFile
!==
"undefined"
&&
imageFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
imageFile
!=
null
).
to
.
equal
(
true
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
const
imageFile2
=
zip
.
files
[
"word/media/image_generated_2.png"
];
const
imageFile2
=
zip
.
files
[
"word/media/image_generated_2.png"
];
expect
(
(
typeof
imageFile2
!==
"undefined"
&&
imageFile2
!==
null
)
).
to
.
equal
(
true
);
expect
(
imageFile2
!=
null
).
to
.
equal
(
true
);
expect
(
imageFile2
.
asText
().
length
).
to
.
be
.
within
(
7177
,
7181
);
expect
(
imageFile2
.
asText
().
length
).
to
.
be
.
within
(
7177
,
7181
);
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
expect
(
(
typeof
relsFile
!==
"undefined"
&&
relsFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
relsFile
!=
null
).
to
.
equal
(
true
);
const
relsFileContent
=
relsFile
.
asText
();
const
relsFileContent
=
relsFile
.
asText
();
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/><Relationship Id=
\"
rId7
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_2.png
\"
/></Relationships>"
);
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering
\"
Target=
\"
numbering.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes
\"
Target=
\"
footnotes.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes
\"
Target=
\"
endnotes.xml
\"
/><Relationship Id=
\"
hId0
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header0.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/><Relationship Id=
\"
rId7
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_2.png
\"
/></Relationships>"
);
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
expect
(
(
typeof
documentFile
!==
"undefined"
&&
documentFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
documentFile
!=
null
).
to
.
equal
(
true
);
const
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
});
const
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
});
fs
.
writeFile
(
"test_multi.docx"
,
buffer
);
fs
.
writeFile
(
"test_multi.docx"
,
buffer
);
});
});
...
@@ -185,31 +185,31 @@ describe("image adding with {% image} syntax", function () {
...
@@ -185,31 +185,31 @@ describe("image adding with {% image} syntax", function () {
const
zip
=
out
.
getZip
();
const
zip
=
out
.
getZip
();
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
const
imageFile
=
zip
.
files
[
"word/media/image_generated_1.png"
];
expect
(
(
typeof
imageFile
!==
"undefined"
&&
imageFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
imageFile
!=
null
).
to
.
equal
(
true
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
expect
(
imageFile
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
const
imageFile2
=
zip
.
files
[
"word/media/image_generated_2.png"
];
const
imageFile2
=
zip
.
files
[
"word/media/image_generated_2.png"
];
expect
(
(
typeof
imageFile2
!==
"undefined"
&&
imageFile2
!==
null
)
).
to
.
equal
(
true
);
expect
(
imageFile2
!=
null
).
to
.
equal
(
true
);
expect
(
imageFile2
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
expect
(
imageFile2
.
asText
().
length
).
to
.
be
.
within
(
17417
,
17440
);
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
const
relsFile
=
zip
.
files
[
"word/_rels/document.xml.rels"
];
expect
(
(
typeof
relsFile
!==
"undefined"
&&
relsFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
relsFile
!=
null
).
to
.
equal
(
true
);
const
relsFileContent
=
relsFile
.
asText
();
const
relsFileContent
=
relsFile
.
asText
();
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header1.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer
\"
Target=
\"
footer1.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable
\"
Target=
\"
fontTable.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/></Relationships>"
);
expectNormalCharacters
(
relsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header1.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer
\"
Target=
\"
footer1.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable
\"
Target=
\"
fontTable.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/></Relationships>"
);
const
headerRelsFile
=
zip
.
files
[
"word/_rels/header1.xml.rels"
];
const
headerRelsFile
=
zip
.
files
[
"word/_rels/header1.xml.rels"
];
expect
(
(
typeof
headerRelsFile
!==
"undefined"
&&
headerRelsFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
headerRelsFile
!=
null
).
to
.
equal
(
true
);
const
headerRelsFileContent
=
headerRelsFile
.
asText
();
const
headerRelsFileContent
=
headerRelsFile
.
asText
();
expectNormalCharacters
(
headerRelsFileContent
,
`<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image_generated_2.png"/>
expectNormalCharacters
(
headerRelsFileContent
,
`<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header1.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image_generated_2.png"/>
</Relationships>`
);
</Relationships>`
);
const
footerRelsFile
=
zip
.
files
[
"word/_rels/footer1.xml.rels"
];
const
footerRelsFile
=
zip
.
files
[
"word/_rels/footer1.xml.rels"
];
expect
(
(
typeof
footerRelsFile
!==
"undefined"
&&
footerRelsFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
footerRelsFile
!=
null
).
to
.
equal
(
true
);
const
footerRelsFileContent
=
footerRelsFile
.
asText
();
const
footerRelsFileContent
=
footerRelsFile
.
asText
();
expectNormalCharacters
(
footerRelsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header1.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer
\"
Target=
\"
footer1.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable
\"
Target=
\"
fontTable.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
expectNormalCharacters
(
footerRelsFileContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?><Relationships xmlns=
\"
http://schemas.openxmlformats.org/package/2006/relationships
\"
><Relationship Id=
\"
rId1
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles
\"
Target=
\"
styles.xml
\"
/><Relationship Id=
\"
rId2
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/header
\"
Target=
\"
header1.xml
\"
/><Relationship Id=
\"
rId3
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer
\"
Target=
\"
footer1.xml
\"
/><Relationship Id=
\"
rId4
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable
\"
Target=
\"
fontTable.xml
\"
/><Relationship Id=
\"
rId5
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings
\"
Target=
\"
settings.xml
\"
/><Relationship Id=
\"
rId6
\"
Type=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
\"
Target=
\"
media/image_generated_1.png
\"
/></Relationships>"
);
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
const
documentFile
=
zip
.
files
[
"word/document.xml"
];
expect
(
(
typeof
documentFile
!==
"undefined"
&&
documentFile
!==
null
)
).
to
.
equal
(
true
);
expect
(
documentFile
!=
null
).
to
.
equal
(
true
);
const
documentContent
=
documentFile
.
asText
();
const
documentContent
=
documentFile
.
asText
();
expectNormalCharacters
(
documentContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><w:document xmlns:o=
\"
urn:schemas-microsoft-com:office:office
\"
xmlns:r=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships
\"
xmlns:v=
\"
urn:schemas-microsoft-com:vml
\"
xmlns:w=
\"
http://schemas.openxmlformats.org/wordprocessingml/2006/main
\"
xmlns:w10=
\"
urn:schemas-microsoft-com:office:word
\"
xmlns:wp=
\"
http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing
\"
><w:body><w:p><w:pPr><w:pStyle w:val=
\"
Normal
\"
/><w:rPr></w:rPr></w:pPr><w:r><w:rPr></w:rPr></w:r></w:p><w:sectPr><w:headerReference w:type=
\"
default
\"
r:id=
\"
rId2
\"
/><w:footerReference w:type=
\"
default
\"
r:id=
\"
rId3
\"
/><w:type w:val=
\"
nextPage
\"
/><w:pgSz w:w=
\"
12240
\"
w:h=
\"
15840
\"
/><w:pgMar w:left=
\"
1800
\"
w:right=
\"
1800
\"
w:header=
\"
720
\"
w:top=
\"
2810
\"
w:footer=
\"
1440
\"
w:bottom=
\"
2003
\"
w:gutter=
\"
0
\"
/><w:pgNumType w:fmt=
\"
decimal
\"
/><w:formProt w:val=
\"
false
\"
/><w:textDirection w:val=
\"
lrTb
\"
/><w:docGrid w:type=
\"
default
\"
w:linePitch=
\"
249
\"
w:charSpace=
\"
2047
\"
/></w:sectPr></w:body></w:document>"
);
expectNormalCharacters
(
documentContent
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
yes
\"
?><w:document xmlns:o=
\"
urn:schemas-microsoft-com:office:office
\"
xmlns:r=
\"
http://schemas.openxmlformats.org/officeDocument/2006/relationships
\"
xmlns:v=
\"
urn:schemas-microsoft-com:vml
\"
xmlns:w=
\"
http://schemas.openxmlformats.org/wordprocessingml/2006/main
\"
xmlns:w10=
\"
urn:schemas-microsoft-com:office:word
\"
xmlns:wp=
\"
http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing
\"
><w:body><w:p><w:pPr><w:pStyle w:val=
\"
Normal
\"
/><w:rPr></w:rPr></w:pPr><w:r><w:rPr></w:rPr></w:r></w:p><w:sectPr><w:headerReference w:type=
\"
default
\"
r:id=
\"
rId2
\"
/><w:footerReference w:type=
\"
default
\"
r:id=
\"
rId3
\"
/><w:type w:val=
\"
nextPage
\"
/><w:pgSz w:w=
\"
12240
\"
w:h=
\"
15840
\"
/><w:pgMar w:left=
\"
1800
\"
w:right=
\"
1800
\"
w:header=
\"
720
\"
w:top=
\"
2810
\"
w:footer=
\"
1440
\"
w:bottom=
\"
2003
\"
w:gutter=
\"
0
\"
/><w:pgNumType w:fmt=
\"
decimal
\"
/><w:formProt w:val=
\"
false
\"
/><w:textDirection w:val=
\"
lrTb
\"
/><w:docGrid w:type=
\"
default
\"
w:linePitch=
\"
249
\"
w:charSpace=
\"
2047
\"
/></w:sectPr></w:body></w:document>"
);
fs
.
writeFile
(
"test_header_footer.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
fs
.
writeFile
(
"test_header_footer.docx"
,
zip
.
generate
({
type
:
"nodebuffer"
}));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment