none
convert div content to pdf RRS feed

  • Question

  • how to convert the page content to pdf and download with all styles and content same as in page in C# with out using any dll?

    Wednesday, February 1, 2017 4:35 AM

All replies

  • I dont think there is any way without DLL's . I used third party muhimbi pdf converter and achieved the same.
    Wednesday, February 1, 2017 6:04 AM
  • is their a way to do the same using jquery or javascript.

    I used jsPDF plugin, but the styles did not apply, only the text content were displayed.

    Thankyou

    Wednesday, February 1, 2017 7:25 AM
  • Hi,

    Please check the code below:

    HTML:

    <div id="content">
         <h3>Hello, this is a H3 tag</h3>
    
        <p>a pararaph</p>
    </div>
    <div id="editor"></div>
    <button id="cmd">generate PDF</button>

    JavaScript:

    var doc = new jsPDF();
    var specialElementHandlers = {
        '#editor': function (element, renderer) {
            return true;
        }
    };
    
    $('#cmd').click(function () {
        doc.fromHTML($('#content').html(), 15, 15, {
            'width': 170,
                'elementHandlers': specialElementHandlers
        });
        doc.save('sample-file.pdf');
    });

    More information:

    http://jsfiddle.net/5ud8jkvf/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, February 7, 2017 7:06 AM
    Moderator
  • another way is to use browser's print functionality, but in this case users will need to choose PDF printer in printers list by themselves (also they may not have it). So jsPDF looks as optimal solution here.

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    Tuesday, February 7, 2017 2:38 PM
  • Hi,

    like said Dennis you can use jsPDF (javascript library) for your purpose, I used it personally for a project and works really well.

    I suggest you my blog post like a demo and taking confidence:

    http://www.delucagiuliano.com/how-to-create-a-pdf-client-side-with-javascript

    Kind regards,


    Giuliano De Luca - MCSD SharePoint, MCSD Web Applications, MCPS, MS. www.delucagiuliano.com Twitter: @giuleon Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Tuesday, February 7, 2017 3:17 PM