Gistrec

DesiteMD Create PDF

Dec 5th, 2018
336
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createPDF(fileName) {
  2.     console.log('Read json file')
  3.     fileContent = desiteAPI.readTextFileAsString(fileName);
  4.     fileContent = JSON.parse(fileContent);
  5.  
  6.     console.log('Set default values')
  7.     desiteMD.setPageMargins(20, 20, 20, 20);
  8.     desiteMD.setOrientation(0) ;
  9.     desiteMD.setPaperSize(0);
  10.  
  11.     console.log('Create html tamplate')
  12.     var template = ''
  13.  
  14.     template += '<html>'
  15.     template += '<head>'
  16.     template += '<meta http-equiv="content-type" content="text/html; charset="ISO-8859-1"/>'
  17.     template += '</head>'
  18.     template += '<body>'
  19.  
  20.     for (id in fileContent.DAMAGES) {
  21.         damage = fileContent.DAMAGES[id]
  22.  
  23.         imagePath =  desiteAPI.getProjectDirectory() + "/INSPECTION/img/" + damage.image;
  24.         image = desiteAPI.readTextFile(imagePath)
  25.  
  26.         template += '\
  27.             <div>\
  28.                 <img width="600" src="' + image + '"/>\
  29.                 <br>\
  30.                 <h3>S = ' + damage.S+ '  V = ' + damage.S + '  D = ' + damage.D + '</h3>\
  31.                 <div>Damage name: ' + damage.DAMAGESName + '\
  32.                 <div>' + damage.description + '\
  33.                 <br><br>\
  34.             <div>'
  35.     }
  36.     template += '</body>'
  37.     template += '</html>'
  38.  
  39.  
  40.  
  41.     var htmlPath = desiteAPI.getProjectDirectory() + "/desite.modules/pruefung.module/PDF/pdf_test.html"
  42.     desiteAPI.writeFile(htmlPath, template);
  43.  
  44.     var pdfPath = desiteAPI.getProjectDirectory() + "/desite.modules/pruefung.module/PDF/pdf_test.pdf"
  45.  
  46.     var result = desiteMD.createPdfByTemplate( htmlPath, pdfPath);
  47.     alert('Save as ' + pdfPath)
  48. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment