From 00fcbf31308111ccb3ec36810780f98607391c28 Mon Sep 17 00:00:00 2001
From: Simon Legner Font-metrics-based line sizing and split
Run Code
This (BETA level. API is subject to change!) plugin allows one to scrape formatted text from an HTML - fragment into PDF. Font size, styles are copied. The long-running text is split to stated content width. -
-This is a new paragraph.
- This is more wrapping-less text. -This paragraph will NOT be - on resulting PDF because a special attached element handler will be looking for the ID - 'bypassme' - and - should bypass rendering it.
-This is another - paragraph.
-I want to hide this particular word
-- Integer dignissim urna tortor? Cum rhoncus, a lacus ultricies tincidunt, tristique lundium enim urna, - magna? Sed, enim penatibus? Lacus pellentesque integer et pulvinar tortor? Dapibus in arcu arcu, vut - dolor? Et! Placerat pulvinar cursus, urna ultrices arcu nunc, a ultrices dictumst elementum? Magnis - rhoncus pellentesque, egestas enim purus, augue et nascetur sociis enim rhoncus. Adipiscing augue placerat - tincidunt pulvinar ridiculus. Porta in sociis arcu et placerat augue sit enim nec hac massa, turpis - ridiculus nunc phasellus pulvinar proin sit pulvinar, ultrices aliquet placerat amet? Lorem nunc porttitor - etiam risus tempor placerat amet non hac, nunc sed odio augue? Turpis, magnis. Lorem pid, a porttitor - tincidunt adipiscing sagittis pellentesque, mattis amet, duis proin, penatibus lectus lorem eros, nisi, - tempor phasellus, elit. -
-- NOTES: the img src must be on the same domain or the external domain should allow Cross-origin. -
- - -HTML Table:
-- NOTES: Must set the COLGROUP tag with "with" on each COL tag as %, inspect the table. BTW the css does not - have a good style to render the table on the html :P, feel free to the add the CSS. -
-- Heading1 - | -- Heading2 - | -
---|---|
- cell 1,1 - | -- cell 1,2 - | -
- cell 2,1 - | -- cell 2,2 - | -
- cell 3,1 - | -- cell 3,2 - | -
- cell 4,1 - | -- cell 4,2 - | -
HTML Lists:
--
var pdf = new jsPDF('p', 'pt', 'letter') - -// source can be HTML-formatted string, or a reference -// to an actual DOM element from which the text will be scraped. -, source = $('#fromHTMLtestdiv')[0] - -// we support special element handlers. Register them with jQuery-style -// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) -// There is no support for any other type of selectors -// (class, of compound) at this time. -, specialElementHandlers = { - // element with id of "bypass" - jQuery style selector - '#bypassme': function(element, renderer){ - // true = "handled elsewhere, bypass text extraction" - return true - }, - '.hide': function(element, renderer){ - // true = "handled elsewhere, bypass text extraction" - return true - } -} - -margins = { - top: 80, - bottom: 60, - left: 40, - width: 522 - }; - // all coords and widths are in jsPDF instance's declared units - // 'inches' in this case -pdf.fromHTML( - source // HTML string or DOM elem ref. - , margins.left // x coord - , margins.top // y coord - , { - 'width': margins.width // max width of content on PDF - , 'elementHandlers': specialElementHandlers - }, - function (dispose) { - // dispose: object with X, Y of the last line add to the PDF - // this allow the insertion of new lines after html - pdf.save('Test.pdf'); - }, - margins - ) - -- -
diff --git a/examples/js/basic.js b/examples/js/basic.js
index 7b8d415d4..fac12cfbc 100644
--- a/examples/js/basic.js
+++ b/examples/js/basic.js
@@ -318,52 +318,6 @@ function demoStringSplitting() {
pdf.save("Test.pdf");
}
-function demoFromHTML() {
- var pdf = new jsPDF("p", "pt", "letter"),
- // source can be HTML-formatted string, or a reference
- // to an actual DOM element from which the text will be scraped.
- source = document.getElementById("fromHTMLtestdiv"),
- // we support special element handlers. Register them with jQuery-style
- // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
- // There is no support for any other type of selectors
- // (class, of compound) at this time.
- specialElementHandlers = {
- // element with id of "bypass" - jQuery style selector
- "#bypassme": function(element, renderer) {
- // true = "handled elsewhere, bypass text extraction"
- return true;
- },
- ".hide": function(element, renderer) {
- // true = "handled elsewhere, bypass text extraction"
- return true;
- }
- };
-
- var margins = {
- top: 80,
- bottom: 60,
- left: 40,
- width: 522
- };
- // all coords and widths are in jsPDF instance's declared units
- // 'inches' in this case
- pdf.fromHTML(
- source, // HTML string or DOM elem ref.
- margins.left, // x coord
- margins.top, // y coord
- {
- width: margins.width, // max width of content on PDF
- elementHandlers: specialElementHandlers
- },
- function(dispose) {
- // dispose: object with X, Y of the last line add to the PDF
- // this allow the insertion of new lines after html
- pdf.save("Test.pdf");
- },
- margins
- );
-}
-
function demoTextAlign() {
var pdf = new jsPDF("p", "pt", "letter");
diff --git a/examples/js/from-html.js b/examples/js/from-html.js
deleted file mode 100644
index 156b8a02a..000000000
--- a/examples/js/from-html.js
+++ /dev/null
@@ -1,18 +0,0 @@
-var doc = new jsPDF();
-
-// We'll make our own renderer to skip this editor
-var specialElementHandlers = {
- "#editor": function(element, renderer) {
- return true;
- },
- ".controls": function(element, renderer) {
- return true;
- }
-};
-
-// All units are in the set measurement for the document
-// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
-doc.fromHTML($("body").get(0), 15, 15, {
- width: 170,
- elementHandlers: specialElementHandlers
-});
diff --git a/modules.conf.js b/modules.conf.js
index 879b025ad..326a45312 100644
--- a/modules.conf.js
+++ b/modules.conf.js
@@ -383,15 +383,6 @@ var configuration = {
description: '',
deps: []
},
- 'from_html': {
- name: 'FromHTML Plugin',
- folder: 'deprecated',
- description: 'Deprecated',
- deps: [
- 'jspdf',
- 'cell'
- ]
- },
'html2pdf': {
name: 'html2pdf Plugin',
diff --git a/types/index.d.ts b/types/index.d.ts
index 4b51217a8..eff4a6d99 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -817,7 +817,6 @@ declare module "jspdf" {
* - Cell
* - Context2D
* - fileloading
- * - FromHTML
* - html
* - JavaScript
* - split_text_to_size
@@ -947,16 +946,6 @@ declare module "jspdf" {
// jsPDF plugin: html
html(src: string | HTMLElement, options?: HTMLOptions): Promise