Compare commits

..

No commits in common. '9c1397b46f69eba2b458f5d2f8c42ffc4fcc1f82' and '2fcc9c97f2ef3773fd417e803b7a8ffbe0ab06c8' have entirely different histories.

  1. BIN
      public/images/resized/sampleImage.png
  2. 12
      services/user.js
  3. BIN
      template/Hform4.docx
  4. 51
      tools/addImageToWord.js

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

@ -3,8 +3,7 @@ const jalali = require("jalali-moment");
const persianjs = require('persianjs')
const docxTemp = require('../tools/docxtemp')
const imageResizer = require('../tools/imageResizer')
const addImageToWord = require('../tools/addImageToWord');
const { result } = require('lodash');
const addImageToWord = require('../tools/addImageToWord')
let methods = {}
@ -44,7 +43,7 @@ methods.addUser = (userInfo,imgOriginalName) => {
imageResizer(imgOriginalName)
.then(()=>{
return models.User.create(userInfo)
models.User.create(userInfo)
}).then((user) => {
resolve(user)
@ -61,11 +60,10 @@ methods.addUser = (userInfo,imgOriginalName) => {
methods.completeForm =(userId)=>{
return new Promise((resolve, reject) => {
let userInfo;
privates.findUser(userId)
.then(user=>{
userInfo = user
let userInfo = user
userInfo.fullName = user.firstName + ' ' + user.lastName
@ -90,9 +88,7 @@ methods.completeForm =(userId)=>{
return docxTemp(userInfo, userInfo.fileName)
}).then(docxFileName=>{
return addImageToWord(docxFileName, userInfo.imageFileName + '.png')
}).then(result=>{
resolve(`localhost:3000/users/download/${result}`)
addImageToWord(docxFileName, userInfo.fileName + '.png')
}).catch(err => {
if (err.eText) {

Binary file not shown.

@ -1,47 +1,16 @@
const exec = require('child-process-promise').exec;
const fsPromises = require('fs').promises;
const path = require('path')
module.exports = function (docxFile, image) {
return new Promise((resolve, reject) => {
let zipName = docxFile.slice(0, -5) + '.zip'
let filePath = path.join(__dirname + '/../public/files')
exec('mkdir -p word/media')
module.exports = function (docxFile, image){
return new Promise ((resolve, reject)=>{
exec('mkdir word/media')
.then(function (result) {
return Promise.all([
fsPromises.copyFile(path.join(__dirname + '/../public/images/resized/' + image),
path.join(__dirname + '/../public/files/word/media/image2.png')),
fsPromises.rename(path.join(__dirname + '/../public/files/' + docxFile),
path.join(__dirname + '/../public/files/' + zipName))
])
}).then((result) => {
return exec(`zip -d ${zipName} ./word/media/image2.png`, {
cwd: filePath
})
}).then((result) => {
return exec(`zip -u ${zipName} ./word/media/image2.png`, {
cwd: filePath
var stdout = result.stdout;
var stderr = result.stderr;
console.log('stdout: ', stdout);
console.log('stderr: ', stderr);
})
}).then((result) => {
return fsPromises.rename(path.join(__dirname + '/../public/files/' + zipName),
path.join(__dirname + '/../public/files/' + docxFile))
}).then(() => {
resolve(docxFile)
})
.catch(function (err) {
reject({
eCode: 500,
eText: err
})
console.error('ERROR: ', err);
});
})
}
}
)}
Loading…
Cancel
Save