简体   繁体   English

如何在没有任何库的情况下在JavaScript中拍摄快照并转换为HTML页面的PDF?

[英]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. 这个完整的html是在执行了所有服务器端和客户端代码之后呈现的DOM。 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 . 现在我有了这个完整页面DOM的浏览器视图,我只想获取特定部分的SnapShot,例如具有id = my-required-section的特定div的浏览器视图。

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 ) 让我们假设从<html></html>此DOM的完整快照,而不是只裁剪一个部分(由ID为my-required-section DIV表示)

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. 我在特定的DIV中有完整的HTML代码。 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 但是我怎样才能获得它的父元素的CSS属性,因为当我们通过Chrome开发人员工具通过Inspect元素看到它时,我想要的是该div的精确设计快照

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. 如果是这样,我会建议查看css选择器 ,因为它们可能用于检索网页的特定元素。 In your example, you may retrieve the selected element using document.getElementById("my-required-section"); 在您的示例中,您可以使用document.getElementById("my-required-section");检索所选元素document.getElementById("my-required-section");

jsfiddle (be sure to have console open) jsfiddle(一定要打开控制台)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在javascript中以特定格式转换日期? 不使用任何库 - How can i convert date in specific format in javascript? Without using any library 如何使用 javascript 将 html 页面转换为 pdf - How to convert html page to a pdf using javascript 如何在 JavaScript 中将 HTML 转换为 PDF 生成的字符串? - How can I convert HTML to string for PDF generation in JavaScript? 如何使用Javascript将HTML / CSS转换为PDF? - How can I convert HTML/CSS to PDF using Javascript? 如何在没有任何第三方库的情况下使用javascript将html div元素内的所有元素转换为图像 - How to convert all elements inside html div element into an image using javascript without any third party library 如何抓取HTML5网站并将其HTML内容转换为PDF(使用Python或Ruby库)? - How can I crawl an HTML5 website and convert its HTML content to PDF (using a Python or Ruby library)? 如何在 JavaScript 中转换多页 PDF 中的 HTML 页面 - How to convert HTML page in multi page PDF in JavaScript 如何将使用javascript的网页转换为纯HTML? - How can I convert web page with javascript to plain html? 我可以使用 javascript 修改 PDF 的 Javascript 部分吗 - Can I modify the Javascript section of a PDF with javascript 如何在不使用IFrame的情况下在页面上显示PDF的HTML5转换? - How to display HTML5 convert of a PDF on page without using an IFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM