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
b3c9b13a
Commit
b3c9b13a
authored
Feb 19, 2015
by
Edgar Hipp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qrcode decoding works with multiple images
parent
2cd4c09c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
23 deletions
+47
-23
coffee/index.coffee
+11
-5
coffee/test.coffee
+36
-18
No files found.
coffee/index.coffee
View file @
b3c9b13a
...
...
@@ -79,12 +79,18 @@ class ImageModule
imR
.
popQrQueue
=
(
num
)
=>
found
=
@
qrQueue
.
indexOf
(
num
)
if
found
!=-
1
@
qrQueue
.
splice
(
found
)
else
throw
new
Error
(
"qrqueue
#{
num
}
is not in qrqueue"
)
@
qrQueue
.
splice
(
found
,
1
)
else
@
on
(
'error'
,
new
Error
(
"qrqueue
#{
num
}
is not in qrqueue"
)
)
if
@
qrQueue
.
length
==
0
then
@
finished
()
imR
.
findImages
()
.
replaceImages
()
try
imR
.
findImages
()
.
replaceImages
()
catch
e
@
on
(
'error'
,
e
)
on
:
(
event
,
data
)
->
if
event
==
'error'
throw
data
handle
:
(
type
,
data
)
->
if
type
==
'replaceTag'
and
data
==
'image'
@
replaceTag
()
...
...
coffee/test.coffee
View file @
b3c9b13a
...
...
@@ -7,6 +7,7 @@ fileNames=[
'imageLoopExample.docx'
,
'imageInlineExample.docx'
,
'qrExample.docx'
,
'qrExample2.docx'
,
]
ImageModule
=
require
(
'../js/index.js'
)
...
...
@@ -136,45 +137,62 @@ describe 'qrcode replacing',->
d
imageModule
.
finished
=
()
->
zip
=
doc
.
getZip
()
zip
=
doc
X
[
name
]
.
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr.docx"
,
buffer
);
done
()
doc
=
docX
[
name
]
doc
X
[
name
]
=
docX
[
name
]
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'image'
})
doc
.
attachModule
(
imageModule
)
doc
X
[
name
]
.
attachModule
(
imageModule
)
doc
doc
X
[
name
]
.
render
()
it
'should work with simple'
,
->
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
2
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
17417
)
describe
'should work with two'
,
->
zip
=
null
before
(
done
)
->
name
=
'qrExample2.docx'
# imageFile=zip.files['word/media/image_generated_1.png']
# expect(imageFile?).to.equal(true)
# expect(imageFile.asText().length).to.equal(17417)
imageModule
=
new
ImageModule
({
qrCode
:
true
})
# imageFile2=zip.files['word/media/image_generated_2.png']
# expect(imageFile2?).to.equal(true
)
# expect(imageFile2.asText().length).to.equal(7177)
imageModule
.
getImageFromData
=
(
imgData
)
->
d
=
fs
.
readFileSync
(
'examples/'
+
imgData
,
'binary'
)
d
# 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>""")
imageModule
.
finished
=
()
->
zip
=
docX
[
name
].
getZip
()
buffer
=
zip
.
generate
({
type
:
"nodebuffer"
})
fs
.
writeFile
(
"test_qr2.docx"
,
buffer
);
done
()
docX
[
name
]
=
docX
[
name
]
.
load
(
docX
[
name
].
loadedContent
)
.
setData
({
image
:
'image'
,
image2
:
'image2.png'
})
# 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>""")
docX
[
name
].
attachModule
(
imageModule
)
docX
[
name
]
.
render
()
it
'should work with two'
,
->
images
=
zip
.
file
(
/media\/.*.png/
)
expect
(
images
.
length
).
to
.
equal
(
4
)
expect
(
images
[
0
].
asText
().
length
).
to
.
equal
(
859
)
expect
(
images
[
1
].
asText
().
length
).
to
.
equal
(
826
)
expect
(
images
[
2
].
asText
().
length
).
to
.
equal
(
17417
)
expect
(
images
[
3
].
asText
().
length
).
to
.
equal
(
7177
)
# it 'should work with inline images',()->
...
...
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