Generate pdf from HTML in div using Javascript

前端 未结 12 1319
你的背包
你的背包 2020-11-22 06:10

I have the following html code:



    
        

don\'t print th

12条回答
  •  半阙折子戏
    2020-11-22 06:51

    To capture div as PDF you can use https://grabz.it solution. It's got a JavaScript API which is easy and flexible and will allow you to capture the contents of a single HTML element such as a div or a span

    In order to implement it you will need to first get an app key and secret and download the (free) SDK.

    And now an example.

    Let's say you have the HTML:

    Acme Camera

    $399
    4.5 out of 5

    Cras ut velit sed purus porttitor aliquam. Nulla tristique magna ac libero tempor, ac vestibulum felisvulput ate. Nam ut velit eget risus porttitor tristique at ac diam. Sed nisi risus, rutrum a metus suscipit, euismod tristique nulla. Etiam venenatis rutrum risus at blandit. In hac habitasse platea dictumst. Suspendisse potenti. Phasellus eget vehicula felis.

    To capture what is under the features id you will need to:

    //add the sdk
    
    
    

    Please note the target: #feature. #feature is you CSS selector, like in the previous example. Now, when the page is loaded an image screenshot will now be created in the same location as the script tag, which will contain all of the contents of the features div and nothing else.

    The are other configuration and customization you can do to the div-screenshot mechanism, please check them out here

提交回复
热议问题