JSFiddle - React, Tailwind, and code Playground

by viswa317

HTML

<script src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
<div id="inspectionReport">
    <div class="title">
        <p class="appname">Title</p>
        <p>REPORT</p>
    </div>
    <p class="date">Revised on 9/3/2013</p>
    <p style="float:right;">
        <button onclick="javascript:demoFromHTML();">Generate Pdf</button>
    </p>
    <table style="width:100%">
        <tbody>
            <tr>
                <td>A No : <span id="a">1</span>
                </td>
                <td>B / No : <span id="b">2</span>
                </td>
                <td>C Date: <span id="c"></span>
                </td>
            </tr>
            <tr>
                <td>A No : <span id="d">3</span>
                </td>
                <td>B name: <span id="e">4</span>
                </td>
                <td>
                    <p>C [ X ] D [ ]</p>
                    <p>G Date : <span id="f"></span>
                    </p>
                </td>
            </tr>
            <tr>
                <td>O No : <span id="yy"></span>
                </td>
                <td>Orgin : <span id="yyr"></span>
                </td>
                <td>S : [ X ] G [ ] J [ X ] Y [ X ] G</td>
            </tr>
            <tr>
                <td></td>
                <td>Name : <span id="QW"></span>
                </td>
                <td>xc : <span id="FG"></span>
                </td>
            </tr>
            <tr>
                <td>No : <span id="gg"></span>
                </td>
                <td>company : <span id="gg"></span>
                </td>
                <td>type t [ ] A [ X ] No</td>
            </tr>
            <tr>
                <td>Quen : <span id="odrQuan"></span>
                </td>
                <td>Sh : <span id="shipQuan"></span>
                </td>
                <td>Run [ ] Int [ X ]. Shi [ ] No.</td>
            </tr>
        </tbody>
    </table>
    <table style="width:100%">
        <tbody>
            <tr>
        ...

CSS

button {
		    margin-top: 5%;
		}
		.title {
		    text-align : center;
		    margin-top: 20px;
		}
		.title .appname {
		    font-weight: bold;
		}
		.boldFont {
		    font-weight: bold;
		}
		.date {
		    text-align : right;
		}
		table, th, td {
		    border: 1px solid black;
		    border-collapse: collapse;
		    margin-bottom: 10px;
		}
		th, td {
		    padding: 5px;
		    vertical-align: top;
		}
		p {
		    margin: 0px;
		}
		.date {
		    margin: 10px 0px 10px 0px;
		}
		.sdate {
		    float : right;
		}

JavaScript

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 = $('#inspectionReport')[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
        }
    };
    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);
}