Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createPDF(fileName) {
- console.log('Read json file')
- fileContent = desiteAPI.readTextFileAsString(fileName);
- fileContent = JSON.parse(fileContent);
- console.log('Set default values')
- desiteMD.setPageMargins(20, 20, 20, 20);
- desiteMD.setOrientation(0) ;
- desiteMD.setPaperSize(0);
- console.log('Create html tamplate')
- var template = ''
- template += '<html>'
- template += '<head>'
- template += '<meta http-equiv="content-type" content="text/html; charset="ISO-8859-1"/>'
- template += '</head>'
- template += '<body>'
- for (id in fileContent.DAMAGES) {
- damage = fileContent.DAMAGES[id]
- imagePath = desiteAPI.getProjectDirectory() + "/INSPECTION/img/" + damage.image;
- image = desiteAPI.readTextFile(imagePath)
- template += '\
- <div>\
- <img width="600" src="' + image + '"/>\
- <br>\
- <h3>S = ' + damage.S+ ' V = ' + damage.S + ' D = ' + damage.D + '</h3>\
- <div>Damage name: ' + damage.DAMAGESName + '\
- <div>' + damage.description + '\
- <br><br>\
- <div>'
- }
- template += '</body>'
- template += '</html>'
- var htmlPath = desiteAPI.getProjectDirectory() + "/desite.modules/pruefung.module/PDF/pdf_test.html"
- desiteAPI.writeFile(htmlPath, template);
- var pdfPath = desiteAPI.getProjectDirectory() + "/desite.modules/pruefung.module/PDF/pdf_test.pdf"
- var result = desiteMD.createPdfByTemplate( htmlPath, pdfPath);
- alert('Save as ' + pdfPath)
- }
Advertisement