diff --git a/src/html2pdf.js b/src/html2pdf.js index 45ae5b0..a6ebe53 100644 --- a/src/html2pdf.js +++ b/src/html2pdf.js @@ -32,356 +32,433 @@ * 'image' ('type' and 'quality'), and 'html2canvas' / 'jspdf', which are * sent as settings to their corresponding functions. */ -var html2pdf = (function(html2canvas, jsPDF) { - - /* ---------- MAIN FUNCTION ---------- */ - - var html2pdf = function(source, opt) { - // Handle input. - opt = objType(opt) === 'object' ? opt : {}; - var source = html2pdf.parseInput(source, opt); - - // Determine the PDF page size. - var pageSize = jsPDF.getPageSize(opt.jsPDF); - pageSize.inner = { - width: pageSize.width - opt.margin[1] - opt.margin[3], - height: pageSize.height - opt.margin[0] - opt.margin[2] - }; - pageSize.inner.ratio = pageSize.inner.height / pageSize.inner.width; - - // Copy the source element into a PDF-styled container div. - var container = html2pdf.makeContainer(source, pageSize); - var overlay = container.parentElement; - - // Get the locations of all hyperlinks. - if (opt.enableLinks) { - // Find all anchor tags and get the container's bounds for reference. - opt.links = []; - var links = container.querySelectorAll('a'); - var containerRect = unitConvert(container.getBoundingClientRect(), pageSize.k); - - // Treat each client rect as a separate link (for text-wrapping). - Array.prototype.forEach.call(links, function(link) { - var clientRects = link.getClientRects(); - for (var i=0; i