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
538f2066
Commit
538f2066
authored
Feb 18, 2015
by
Edgar Hipp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qrCodeModule works now
parent
41ea55c4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
127 additions
and
45 deletions
+127
-45
coffee/docxQrCode.coffee
+5
-5
coffee/imgManager.coffee
+1
-1
coffee/imgReplacer.coffee
+15
-14
coffee/index.coffee
+49
-25
coffee/test.coffee
+57
-0
examples/qrExample.docx
+0
-0
No files found.
coffee/docxQrCode.coffee
View file @
538f2066
...
@@ -7,7 +7,7 @@ JSZip=require('jszip')
...
@@ -7,7 +7,7 @@ JSZip=require('jszip')
QrCode
=
require
(
'qrcode-reader'
)
QrCode
=
require
(
'qrcode-reader'
)
module
.
exports
=
class
DocxQrCode
module
.
exports
=
class
DocxQrCode
constructor
:
(
imageData
,
@
xmlTemplater
,
@
imgName
=
""
,
@
num
,
@
callback
)
->
constructor
:
(
imageData
,
@
xmlTemplater
,
@
imgName
=
""
,
@
num
,
@
getDataFromString
)
->
@
callbacked
=
false
@
callbacked
=
false
@
data
=
imageData
@
data
=
imageData
if
@
data
==
undefined
then
throw
new
Error
(
"data of qrcode can't be undefined"
)
if
@
data
==
undefined
then
throw
new
Error
(
"data of qrcode can't be undefined"
)
...
@@ -20,9 +20,9 @@ module.exports= class DocxQrCode
...
@@ -20,9 +20,9 @@ module.exports= class DocxQrCode
@
qr
=
new
QrCode
()
@
qr
=
new
QrCode
()
@
qr
.
callback
=
()
->
@
qr
.
callback
=
()
->
_this
.
ready
=
true
_this
.
ready
=
true
_this
.
result
=
this
.
result
_this
.
result
=
@
result
testdoc
=
new
_this
.
xmlTemplater
.
currentClass
this
.
result
,
_this
.
xmlTemplater
.
toJson
()
testdoc
=
new
_this
.
xmlTemplater
.
currentClass
@
result
,{
Tags
:
_this
.
xmlTemplater
.
Tags
}
testdoc
.
applyTags
()
testdoc
.
render
()
_this
.
result
=
testdoc
.
content
_this
.
result
=
testdoc
.
content
_this
.
searchImage
()
_this
.
searchImage
()
if
DocUtils
.
env
==
'browser'
if
DocUtils
.
env
==
'browser'
...
@@ -34,4 +34,4 @@ module.exports= class DocxQrCode
...
@@ -34,4 +34,4 @@ module.exports= class DocxQrCode
if
err
then
console
.
error
err
if
err
then
console
.
error
err
@
callback
(
this
,
@
imgName
,
@
num
)
@
callback
(
this
,
@
imgName
,
@
num
)
if
!
@
result
?
then
return
cb
()
if
!
@
result
?
then
return
cb
()
@
xmlTemplater
.
DocxGen
.
qrCode
(
@
result
,
cb
)
@
getDataFromString
(
@
result
,
cb
)
coffee/imgManager.coffee
View file @
538f2066
...
@@ -73,7 +73,7 @@ module.exports = class ImgManager
...
@@ -73,7 +73,7 @@ module.exports = class ImgManager
relationships
.
appendChild
newTag
relationships
.
appendChild
newTag
@
setImage
(
"word/_rels/
#{
@
endFileName
}
.xml.rels"
,
DocUtils
.
encode_utf8
DocUtils
.
xml2Str
@
xmlDoc
)
@
setImage
(
"word/_rels/
#{
@
endFileName
}
.xml.rels"
,
DocUtils
.
encode_utf8
DocUtils
.
xml2Str
@
xmlDoc
)
@
maxRid
@
maxRid
getImageName
:
(
id
)
->
getImageName
:
(
id
=
0
)
->
nameCandidate
=
"Copie_"
+
id
+
".png"
nameCandidate
=
"Copie_"
+
id
+
".png"
fullPath
=
@
getFullPath
(
nameCandidate
)
fullPath
=
@
getFullPath
(
nameCandidate
)
if
@
hasImage
(
fullPath
)
if
@
hasImage
(
fullPath
)
...
...
coffee/imgReplacer.coffee
View file @
538f2066
DocUtils
=
require
(
'
docxtemplater'
).
DocUtils
DocUtils
=
require
(
'
./docUtils'
)
DocxQrCode
=
require
(
'./docxQrCode'
)
DocxQrCode
=
require
(
'./docxQrCode'
)
PNG
=
require
(
'png-js'
)
PNG
=
require
(
'png-js'
)
JSZip
=
require
(
'jszip'
)
JSZip
=
require
(
'jszip'
)
module
.
exports
=
class
ImgReplacer
module
.
exports
=
class
ImgReplacer
constructor
:
(
@
xmlTemplater
)
->
constructor
:
(
@
xmlTemplater
,
@
imgManager
)
->
@
imgMatches
=
[]
@
imgMatches
=
[]
@
xmlTemplater
.
numQrCode
=
0
@
xmlTemplater
.
numQrCode
=
0
this
this
...
@@ -20,15 +20,16 @@ module.exports= class ImgReplacer
...
@@ -20,15 +20,16 @@ module.exports= class ImgReplacer
@
xmlTemplater
.
numQrCode
+=
@
imgMatches
.
length
@
xmlTemplater
.
numQrCode
+=
@
imgMatches
.
length
@
replaceImage
(
match
,
u
)
for
match
,
u
in
@
imgMatches
@
replaceImage
(
match
,
u
)
for
match
,
u
in
@
imgMatches
this
this
imageSetter
:
(
docxqrCode
)
-
>
imageSetter
:
(
docxqrCode
)
=
>
if
docxqrCode
.
callbacked
==
true
then
return
if
docxqrCode
.
callbacked
==
true
then
return
docxqrCode
.
callbacked
=
true
docxqrCode
.
callbacked
=
true
docxqrCode
.
xmlTemplater
.
numQrCode
--
docxqrCode
.
xmlTemplater
.
numQrCode
--
docxqrCode
.
xmlTemplater
.
imgManager
.
setImage
(
"word/media/
#{
docxqrCode
.
imgName
}
"
,
docxqrCode
.
data
,{
binary
:
true
})
@
imgManager
.
setImage
(
"word/media/
#{
docxqrCode
.
imgName
}
"
,
docxqrCode
.
data
,{
binary
:
true
})
docxqrCode
.
xmlTemplater
.
DocxGen
.
qrCodeCallBack
(
docxqrCode
.
xmlTemplat
er
.
fileName
+
'-'
+
docxqrCode
.
num
,
false
)
@
popQrQueue
(
@
imgManag
er
.
fileName
+
'-'
+
docxqrCode
.
num
,
false
)
replaceImage
:
(
match
,
u
)
->
replaceImage
:
(
match
,
u
)
->
num
=
@
xmlTemplater
.
DocxGen
.
qrCodeNumCallBack
num
=
parseInt
(
Math
.
random
()
*
10000
)
@
xmlTemplater
.
DocxGen
.
qrCodeNumCallBack
++
# num=@xmlTemplater.DocxGen.qrCodeNumCallBack
# @xmlTemplater.DocxGen.qrCodeNumCallBack++
try
try
xmlImg
=
DocUtils
.
Str2xml
'<?xml version="1.0" ?><w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">'
+
match
[
0
]
+
'</w:document>'
,(
_i
,
type
)
->
if
_i
==
'fatalError'
then
throw
"fatalError"
xmlImg
=
DocUtils
.
Str2xml
'<?xml version="1.0" ?><w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">'
+
match
[
0
]
+
'</w:document>'
,(
_i
,
type
)
->
if
_i
==
'fatalError'
then
throw
"fatalError"
catch
e
catch
e
...
@@ -36,15 +37,15 @@ module.exports= class ImgReplacer
...
@@ -36,15 +37,15 @@ module.exports= class ImgReplacer
tagrId
=
xmlImg
.
getElementsByTagName
(
"a:blip"
)[
0
]
tagrId
=
xmlImg
.
getElementsByTagName
(
"a:blip"
)[
0
]
if
tagrId
==
undefined
then
throw
new
Error
(
'tagRiD undefined !'
)
if
tagrId
==
undefined
then
throw
new
Error
(
'tagRiD undefined !'
)
rId
=
tagrId
.
getAttribute
(
'r:embed'
)
rId
=
tagrId
.
getAttribute
(
'r:embed'
)
oldFile
=
@
xmlTemplater
.
imgManager
.
getImageByRid
(
rId
)
oldFile
=
@
imgManager
.
getImageByRid
(
rId
)
tag
=
xmlImg
.
getElementsByTagName
(
"wp:docPr"
)[
0
]
tag
=
xmlImg
.
getElementsByTagName
(
"wp:docPr"
)[
0
]
if
tag
==
undefined
then
throw
new
Error
(
'tag undefined'
)
if
tag
==
undefined
then
throw
new
Error
(
'tag undefined'
)
if
tag
.
getAttribute
(
"name"
).
substr
(
0
,
6
)
==
"Copie_"
then
return
#if image is already a replacement then do nothing
if
tag
.
getAttribute
(
"name"
).
substr
(
0
,
6
)
==
"Copie_"
then
return
#if image is already a replacement then do nothing
imgName
=
@
xmlTemplater
.
imgManager
.
getImageName
(
@
xmlTemplater
.
imageId
)
imgName
=
@
imgManager
.
getImageName
(
)
@
xmlTemplater
.
DocxGen
.
qrCodeCallBack
(
@
xmlTemplat
er
.
fileName
+
'-'
+
num
,
true
)
@
pushQrQueue
(
@
imgManag
er
.
fileName
+
'-'
+
num
,
true
)
newId
=
@
xmlTemplater
.
imgManager
.
addImageRels
(
imgName
,
""
)
newId
=
@
imgManager
.
addImageRels
(
imgName
,
""
)
@
xmlTemplater
.
imageId
++
@
xmlTemplater
.
imageId
++
@
xmlTemplater
.
imgManager
.
setImage
(
@
xmlTemplater
.
imgManager
.
getFullPath
(
imgName
),
oldFile
.
data
,{
binary
:
true
})
@
imgManager
.
setImage
(
@
imgManager
.
getFullPath
(
imgName
),
oldFile
.
data
,{
binary
:
true
})
tag
.
setAttribute
(
'name'
,
"
#{
imgName
}
"
)
tag
.
setAttribute
(
'name'
,
"
#{
imgName
}
"
)
tagrId
.
setAttribute
(
'r:embed'
,
"rId
#{
newId
}
"
)
tagrId
.
setAttribute
(
'r:embed'
,
"rId
#{
newId
}
"
)
imageTag
=
xmlImg
.
getElementsByTagName
(
'w:drawing'
)[
0
]
imageTag
=
xmlImg
.
getElementsByTagName
(
'w:drawing'
)[
0
]
...
@@ -52,7 +53,7 @@ module.exports= class ImgReplacer
...
@@ -52,7 +53,7 @@ module.exports= class ImgReplacer
replacement
=
DocUtils
.
xml2Str
imageTag
replacement
=
DocUtils
.
xml2Str
imageTag
@
xmlTemplater
.
content
=
@
xmlTemplater
.
content
.
replace
(
match
[
0
],
replacement
)
@
xmlTemplater
.
content
=
@
xmlTemplater
.
content
.
replace
(
match
[
0
],
replacement
)
if
DocUtils
.
env
==
'browser'
if
DocUtils
.
env
==
'browser'
@
qr
[
u
]
=
new
DocxQrCode
(
oldFile
.
asBinary
(),
@
xmlTemplater
,
imgName
,
num
)
@
qr
[
u
]
=
new
DocxQrCode
(
oldFile
.
asBinary
(),
@
xmlTemplater
,
imgName
,
num
,
@
getDataFromString
)
@
qr
[
u
].
decode
(
@
imageSetter
)
@
qr
[
u
].
decode
(
@
imageSetter
)
else
else
mockedQrCode
=
{
xmlTemplater
:
@
xmlTemplater
,
imgName
:
imgName
,
data
:
oldFile
.
asBinary
(),
num
:
num
}
mockedQrCode
=
{
xmlTemplater
:
@
xmlTemplater
,
imgName
:
imgName
,
data
:
oldFile
.
asBinary
(),
num
:
num
}
...
@@ -64,7 +65,7 @@ module.exports= class ImgReplacer
...
@@ -64,7 +65,7 @@ module.exports= class ImgReplacer
finished
=
(
a
)
=>
finished
=
(
a
)
=>
png
.
decoded
=
a
png
.
decoded
=
a
try
try
@
qr
[
u
]
=
new
DocxQrCode
(
png
,
@
xmlTemplater
,
imgName
,
num
)
@
qr
[
u
]
=
new
DocxQrCode
(
png
,
@
xmlTemplater
,
imgName
,
num
,
@
getDataFromString
)
@
qr
[
u
].
decode
(
@
imageSetter
)
@
qr
[
u
].
decode
(
@
imageSetter
)
catch
e
catch
e
@
imageSetter
(
mockedQrCode
)
@
imageSetter
(
mockedQrCode
)
...
...
coffee/index.coffee
View file @
538f2066
SubContent
=
require
(
'docxtemplater'
).
SubContent
SubContent
=
require
(
'docxtemplater'
).
SubContent
ImgManager
=
require
(
'./imgManager'
)
ImgManager
=
require
(
'./imgManager'
)
ImgReplacer
=
require
(
'./imgReplacer'
)
fs
=
require
(
'fs'
)
fs
=
require
(
'fs'
)
class
ImageModule
class
ImageModule
constructor
:
(
@
options
=
{})
->
constructor
:
(
@
options
=
{})
->
if
!
@
options
.
centered
?
then
@
options
.
centered
=
false
if
!
@
options
.
centered
?
then
@
options
.
centered
=
false
@
qrQueue
=
[]
@
imageNumber
=
1
@
imageNumber
=
1
handleEvent
:
(
event
,
eventData
)
->
handleEvent
:
(
event
,
eventData
)
->
if
event
==
'rendering-file'
if
event
==
'rendering-file'
@
renderingFileName
=
eventData
@
renderingFileName
=
eventData
gen
=
@
manager
.
getInstance
(
'gen'
)
gen
=
@
manager
.
getInstance
(
'gen'
)
@
imgManager
=
new
ImgManager
(
gen
.
zip
,
@
renderingFileName
)
@
imgManager
=
new
ImgManager
(
gen
.
zip
,
@
renderingFileName
)
@
imgManager
.
loadImageRels
()
get
:
(
data
)
->
get
:
(
data
)
->
if
data
==
'loopType'
if
data
==
'loopType'
templaterState
=
@
manager
.
getInstance
(
'templaterState'
)
templaterState
=
@
manager
.
getInstance
(
'templaterState'
)
...
@@ -34,36 +37,57 @@ class ImageModule
...
@@ -34,36 +37,57 @@ class ImageModule
[
150
,
150
]
[
150
,
150
]
getImageFromData
:
(
imgData
)
->
getImageFromData
:
(
imgData
)
->
fs
.
readFileSync
(
imgData
)
fs
.
readFileSync
(
imgData
)
handle
:
(
type
,
data
)
->
replaceTag
:->
if
type
==
'replaceTag'
and
data
==
'image'
scopeManager
=
@
manager
.
getInstance
(
'scopeManager'
)
scopeManager
=
@
manager
.
getInstance
(
'scopeManager'
)
templaterState
=
@
manager
.
getInstance
(
'templaterState'
)
templaterState
=
@
manager
.
getInstance
(
'templaterState'
)
tag
=
templaterState
.
textInsideTag
.
substr
(
1
)
tag
=
templaterState
.
textInsideTag
.
substr
(
1
)
imgData
=
scopeManager
.
getValueFromScope
(
tag
)
imgData
=
scopeManager
.
getValueFromScope
(
tag
)
tagXml
=
@
manager
.
getInstance
(
'xmlTemplater'
).
tagXml
tagXml
=
@
manager
.
getInstance
(
'xmlTemplater'
).
tagXml
startEnd
=
"<
#{
tagXml
}
></
#{
tagXml
}
>"
startEnd
=
"<
#{
tagXml
}
></
#{
tagXml
}
>"
if
imgData
==
'undefined'
then
return
@
replaceBy
(
startEnd
,
tagXml
)
if
imgData
==
'undefined'
then
return
@
replaceBy
(
startEnd
,
tagXml
)
try
try
imgBuffer
=
@
getImageFromData
(
imgData
)
imgBuffer
=
@
getImageFromData
(
imgData
)
catch
e
catch
e
return
@
replaceBy
(
startEnd
,
tagXml
)
return
@
replaceBy
(
startEnd
,
tagXml
)
rId
=
@
imgManager
rId
=
@
imgManager
.
loadImageRels
()
.
loadImageRels
()
.
addImageRels
(
@
getNextImageName
(),
imgBuffer
)
.
addImageRels
(
@
getNextImageName
(),
imgBuffer
)
sizePixel
=
@
getSizeFromData
(
imgBuffer
)
sizePixel
=
@
getSizeFromData
(
imgBuffer
)
size
=
[
@
convertPixelsToEmus
(
sizePixel
[
0
]),
@
convertPixelsToEmus
(
sizePixel
[
1
])]
size
=
[
@
convertPixelsToEmus
(
sizePixel
[
0
]),
@
convertPixelsToEmus
(
sizePixel
[
1
])]
if
@
options
.
centered
==
false
if
@
options
.
centered
==
false
outsideElement
=
tagXml
outsideElement
=
tagXml
newText
=
@
getImageXml
(
rId
,
size
)
newText
=
@
getImageXml
(
rId
,
size
)
if
@
options
.
centered
==
true
if
@
options
.
centered
==
true
outsideElement
=
tagXml
.
substr
(
0
,
1
)
+
':p'
outsideElement
=
tagXml
.
substr
(
0
,
1
)
+
':p'
newText
=
@
getImageXmlCentered
(
rId
,
size
)
newText
=
@
getImageXmlCentered
(
rId
,
size
)
@
replaceBy
(
newText
,
outsideElement
)
@
replaceBy
(
newText
,
outsideElement
)
replaceQr
:->
xmlTemplater
=
@
manager
.
getInstance
(
'xmlTemplater'
)
imR
=
new
ImgReplacer
(
xmlTemplater
,
@
imgManager
)
imR
.
getDataFromString
=
(
result
,
cb
)
=>
cb
(
null
,
@
getImageFromData
(
result
))
imR
.
pushQrQueue
=
(
num
)
=>
@
qrQueue
.
push
(
num
)
imR
.
popQrQueue
=
(
num
)
=>
found
=
@
qrQueue
.
indexOf
(
num
)
if
found
!=-
1
@
qrQueue
.
splice
(
found
)
else
throw
new
Error
(
"qrqueue
#{
num
}
is not in qrqueue"
)
if
@
qrQueue
.
length
==
0
then
@
finished
()
imR
.
findImages
()
.
replaceImages
()
handle
:
(
type
,
data
)
->
if
type
==
'replaceTag'
and
data
==
'image'
@
replaceTag
()
if
type
==
'xmlRendered'
and
@
options
.
qrCode
@
replaceQr
()
null
null
getImageXml
:
(
rId
,
size
)
->
getImageXml
:
(
rId
,
size
)
->
return
"""
return
"""
...
...
coffee/test.coffee
View file @
538f2066
...
@@ -6,6 +6,7 @@ fileNames=[
...
@@ -6,6 +6,7 @@ fileNames=[
'imageExample.docx'
,
'imageExample.docx'
,
'imageLoopExample.docx'
,
'imageLoopExample.docx'
,
'imageInlineExample.docx'
,
'imageInlineExample.docx'
,
'qrExample.docx'
,
]
]
ImageModule
=
require
(
'../js/index.js'
)
ImageModule
=
require
(
'../js/index.js'
)
...
@@ -121,6 +122,62 @@ describe 'image adding with {% image} syntax', ()->
...
@@ -121,6 +122,62 @@ describe 'image adding with {% image} syntax', ()->
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_multi.docx"
,
buffer
);
fs
.
writeFile
(
"test_multi.docx"
,
buffer
);
describe
'qrcode replacing'
,
->
before
(
done
)
->
console
.
log
'before'
name
=
'qrExample.docx'
imageModule
=
new
ImageModule
({
qrCode
:
true
})
imageModule
.
getImageFromData
=
(
imgData
)
->
d
=
fs
.
readFileSync
(
'examples/'
+
imgData
,
'binary'
)
d
imageModule
.
finished
=
()
->
console
.
log
'finished'
zip
=
doc
.
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr.docx"
,
buffer
);
done
()
doc
=
docX
[
name
]
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'image'
})
doc
.
attachModule
(
imageModule
)
doc
.
render
()
it
'shoud work with simple'
,
->
it
'should be 1'
,
->
expect
(
1
).
to
.
equal
(
1
)
# imageFile=zip.files['word/media/image_generated_1.png']
# expect(imageFile?).to.equal(true)
# expect(imageFile.asText().length).to.equal(17417)
# imageFile2=zip.files['word/media/image_generated_2.png']
# expect(imageFile2?).to.equal(true)
# expect(imageFile2.asText().length).to.equal(7177)
# relsFile=zip.files['word/_rels/document.xml.rels']
# expect(relsFile?).to.equal(true)
# relsFileContent=relsFile.asText()
# expect(relsFileContent).to.equal("""<?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>""")
# documentFile=zip.files['word/document.xml']
# expect(documentFile?).to.equal(true)
# documentContent=documentFile.asText()
# # expect(documentContent).to.equal("""<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId6\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:drawing>\n <wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">\n <wp:extent cx=\"1905000\" cy=\"1905000\"/>\n <wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>\n <wp:docPr id=\"2\" name=\"Image 2\" descr=\"description\"/>\n <wp:cNvGraphicFramePr>\n <a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/>\n </wp:cNvGraphicFramePr>\n <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">\n <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">\n <pic:nvPicPr>\n <pic:cNvPr id=\"0\" name=\"Picture 1\" descr=\"description\"/>\n <pic:cNvPicPr>\n <a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/>\n </pic:cNvPicPr>\n </pic:nvPicPr>\n <pic:blipFill>\n <a:blip r:embed=\"rId7\">\n <a:extLst>\n <a:ext uri=\"{28A0092B-C50C-407E-A947-70E740481C1C}\">\n <a14:useLocalDpi xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" val=\"0\"/>\n </a:ext>\n </a:extLst>\n </a:blip>\n <a:srcRect/>\n <a:stretch>\n <a:fillRect/>\n </a:stretch>\n </pic:blipFill>\n <pic:spPr bwMode=\"auto\">\n <a:xfrm>\n <a:off x=\"0\" y=\"0\"/>\n <a:ext cx=\"1905000\" cy=\"1905000\"/>\n </a:xfrm>\n <a:prstGeom prst=\"rect\">\n <a:avLst/>\n </a:prstGeom>\n <a:noFill/>\n <a:ln>\n <a:noFill/>\n </a:ln>\n </pic:spPr>\n </pic:pic>\n </a:graphicData>\n </a:graphic>\n </wp:inline>\n</w:drawing></w:r></w:p><w:p><w:pPr></w:pPr></w:p><w:p><w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"preserve\"></w:t></w:r><w:bookmarkStart w:id=\"20\" w:name=\"_GoBack\"/><w:bookmarkEnd w:id=\"20\"/></w:p><w:sectPr><w:headerReference w:type=\"default\" r:id=\"hId0\"/><w:type w:val=\"continuous\"/><w:pgSz w:w=\"12240\" w:h=\"15840\" w:orient=\"portrait\"/><w:pgMar w:top=\"2810\" w:left=\"1800\" w:right=\"1800\" w:bottom=\"1440\"/><w:cols w:num=\"1\" w:sep=\"off\" w:equalWidth=\"1\"/></w:sectPr></w:body></w:document>""")
# it 'should work with inline images',()->
# it 'should work with inline images',()->
# name='imageInlineExample.docx'
# name='imageInlineExample.docx'
...
...
examples/qrExample.docx
0 → 100644
View file @
538f2066
File added
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