0

I have a page where data is added with the help of html. It includes table also. I want something which convert this data to pdf and then download it.

  • Please add more details to your question. – Christoffer Oct 17 '18 at 10:11
  • How would you like to do this in SharePoint Online? Use Microsoft Flow, SharePoint Designer Workflows, custom Code or the SharePoint User Interface? You can see the various options at blog.muhimbi.com/2017/10/…. Disclaimer, I wrote that blog post so consider me biased. – Jeroen Ritmeijer - Muhimbi Oct 19 '18 at 9:17
0

I wrote once SharePoint ashx handler that can render SharePoint page to PDF. It uses PhantomJS for that. See GitHub project

Regards, Pawel

  • Your solution is a WSP, so it can be used in SharePoint OnPremises only. The question was tagged for SharePoint Online. – MHeld Oct 17 '18 at 15:16
0

You can use jspdf for this requirement.

Sample demo:

<html>
<head>
    <title></title>
    <meta charset="utf-8" />

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
    <!-- Below script will print div with id pdf to a pdf file using jspdf -->
    <script type="text/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 = $('html')[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);
        }
    </script>

</head>
<body>
    <div id="content">
        aaa
    </div>
    <div>
        <table border="1" width="100">
            <tr>
                <td>Name</td>
                <td>Age</td>
            </tr>
            <tr>
                <td>John</td>
                <td>11</td>
            </tr>
            <tr>
                <td>Sam</td>
                <td>13</td>
            </tr>
            <tr>
                <td>Tony</td>
                <td>12</td>
            </tr>
        </table>
    </div>
    <input type="button" onclick="demoFromHTML()" value="Print Contents" id="btnPrint" />
</body>
</html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.