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
84b0e39f
Commit
84b0e39f
authored
Aug 18, 2016
by
Edgar HIPP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fix for doc without rId in rels
parent
17fbf596
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
3 deletions
+17
-3
.eslintignore
+1
-0
.eslintrc
+1
-1
es6/imgManager.js
+5
-2
es6/index.js
+10
-0
No files found.
.eslintignore
View file @
84b0e39f
...
@@ -21,3 +21,4 @@ build/
...
@@ -21,3 +21,4 @@ build/
vendor/
vendor/
js/
js/
test/
test/
coverage/
.eslintrc
View file @
84b0e39f
...
@@ -122,7 +122,7 @@
...
@@ -122,7 +122,7 @@
"no-restricted-syntax": 2,
"no-restricted-syntax": 2,
"no-return-assign": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-script-url": 2,
"no-self-compare":
2
,
"no-self-compare":
0
,
"no-sequences": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-shadow": 0,
"no-shadow-restricted-names": 2,
"no-shadow-restricted-names": 2,
...
...
es6/imgManager.js
View file @
84b0e39f
...
@@ -35,11 +35,14 @@ module.exports = class ImgManager {
...
@@ -35,11 +35,14 @@ module.exports = class ImgManager {
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
const
RidArray
=
[];
const
RidArray
=
[
0
];
const
iterable
=
this
.
xmlDoc
.
getElementsByTagName
(
"Relationship"
);
const
iterable
=
this
.
xmlDoc
.
getElementsByTagName
(
"Relationship"
);
for
(
let
i
=
0
,
tag
;
i
<
iterable
.
length
;
i
++
)
{
for
(
let
i
=
0
,
tag
;
i
<
iterable
.
length
;
i
++
)
{
tag
=
iterable
[
i
];
tag
=
iterable
[
i
];
RidArray
.
push
(
parseInt
(
tag
.
getAttribute
(
"Id"
).
substr
(
3
),
10
));
const
id
=
tag
.
getAttribute
(
"Id"
);
if
(
/^rId
[
0-9
]
+$/
.
test
(
id
))
{
RidArray
.
push
(
parseInt
(
id
.
substr
(
3
),
10
));
}
}
}
this
.
maxRid
=
DocUtils
.
maxArray
(
RidArray
);
this
.
maxRid
=
DocUtils
.
maxArray
(
RidArray
);
this
.
imageRels
=
[];
this
.
imageRels
=
[];
...
...
es6/index.js
View file @
84b0e39f
"use strict"
;
"use strict"
;
const
isNaN
=
function
(
number
)
{
return
!
(
number
===
number
);
};
const
SubContent
=
require
(
"docxtemplater"
).
SubContent
;
const
SubContent
=
require
(
"docxtemplater"
).
SubContent
;
const
ImgManager
=
require
(
"./imgManager"
);
const
ImgManager
=
require
(
"./imgManager"
);
const
ImgReplacer
=
require
(
"./imgReplacer"
);
const
ImgReplacer
=
require
(
"./imgReplacer"
);
...
@@ -131,6 +135,9 @@ class ImageModule {
...
@@ -131,6 +135,9 @@ class ImageModule {
return
null
;
return
null
;
}
}
getImageXml
(
rId
,
size
)
{
getImageXml
(
rId
,
size
)
{
if
(
isNaN
(
rId
))
{
throw
new
Error
(
"rId is NaN, aborting"
);
}
return
`<w:drawing>
return
`<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="
${
size
[
0
]}
" cy="
${
size
[
1
]}
"/>
<wp:extent cx="
${
size
[
0
]}
" cy="
${
size
[
1
]}
"/>
...
@@ -182,6 +189,9 @@ class ImageModule {
...
@@ -182,6 +189,9 @@ class ImageModule {
`
;
`
;
}
}
getImageXmlCentered
(
rId
,
size
)
{
getImageXmlCentered
(
rId
,
size
)
{
if
(
isNaN
(
rId
))
{
throw
new
Error
(
"rId is NaN, aborting"
);
}
return
` <w:p>
return
` <w:p>
<w:pPr>
<w:pPr>
<w:jc w:val="center"/>
<w:jc w:val="center"/>
...
...
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