简体   繁体   中英

How can I take snap shot and convert to PDF of section of HTML page in JavaScript without any Library?

I do not know but This question might have straight forward answer that "Not Possible" ? But I think definately there should be a way to do this, May be using some OS level work. My Question can be better understand by watching this code.

<html>
<head>

</head>
<body>
  <div> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
  <div id="my-required-section"> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
  <div> .......... </div>
</body>

This complete html is the rendered DOM after all server side and client side code has been executed. Now I have Browser view of this complete page DOM, I just want to get SnapShot of a specific part for example the Browser view of a particular div with id = my-required-section .

In Other Word -

Lets suppose take complete snapshot of this DOM from <html> to </html> than crop only a part (represented by that DIV with id my-required-section )

I will be thank full Even if you suggest me a good article related to this kind of problem.

I will add more context to the problem for better understanding the problem.

  1. I have complete HTML code inside a that particular DIV. But How can I get the CSS property of it parent elements, because What I want is exact designed snapshot of that div when we see that by Inspect element through chrome developer tool

Are you trying to retrieve information contained within the Document Object ?

If so, I would advise looking into css selectors , as they may be used to retrieve particular elements of a web page. In your example, you may retrieve the selected element using document.getElementById("my-required-section");

jsfiddle (be sure to have console open)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM