eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.07k stars 1.38k forks source link

Expose html on Worker (or Worker) #258

Open chaim0m opened 4 years ago

chaim0m commented 4 years ago

I would like to add a custom class to each div which is created when a page-break is added (this is already supported by the "createElement" function its just not exposed). In this way I can control the behaviour of the newly added div, mainly I would like to style it not simply as a blank space and also allow for extracting the space out of the table it is in which does not look good. Currently I have a row in the table with very little data a giant empty section inside the cell and then the next page contains the next cell. Here is the code I tried using to capture the html:

var worker = html2pdf();
worker.set(opt).from(finalHtml).then(newHtml => {
       console.log(newHtml)
        return newHtml
                } )

console logs undefined chaining the toContainer and toCanvas methods yields the same undefined

davidmatos-spk commented 4 years ago

Try this code

var worker = html2pdf() .from(model) .set(opt) .toPdf() .get('pdf') .then(function (pdf) { your code here })

chaim0m commented 4 years ago

Try this code

var worker = html2pdf() .from(model) .set(opt) .toPdf() .get('pdf') .then(function (pdf) { your code here })

Thanks but that gives me the already converted PDF and not the html, as I understand it. The object looks something like this:

{ 
   "internal":{ 
      "collections":{  },
      "events":{ 

      },
      "scaleFactor":2.834645669291339,
      "pageSize":{  },
      "pages":[  ]
   },
   "__private__":{  },
   "CapJoinStyles":{  },
   "__acroform__":{ 

   },
   "AcroFormAppearance":{  },
   "AcroForm":{  },
   "color_spaces":{  },
   "decode":{  },
   "image_compression":{  },
   "__arabicParser__":{ 

   },
   "adler32cs":{  },
   "outline":{  },
   "context2d":{  },
   "canvas":{ 
}

The empty objects have data just didnt copy since it is too large. Also I need the html pre conversion to pdf for manipulation not after.