简体   繁体   English

Html DOM 到数组缓冲区为 pdf 制作 BLOB?

[英]Html DOM to Array Buffer to make BLOB for pdf?

I want to show my HTML DOM as pdf in new tab using BLOB.我想使用 BLOB 在新选项卡中将我的 HTML DOM 显示为 pdf。 We can achieve this by calling a API which will return a blob but I want to do this without the involvement of any server side API.我们可以通过调用 API 来实现这一点,它将返回一个 blob,但我想在没有任何服务器端 API 参与的情况下执行此操作。 I am facing problems in converting my html string to ARRAY BUFFER.我在将 html 字符串转换为 ARRAY BUFFER 时遇到问题。 Here is the code on stackblitz you can test this and please let me know how to solve this.这是stackblitz上的代码,您可以对此进行测试,请告诉我如何解决此问题。 Thanks谢谢

generate pdf from html dom从 html dom 生成 pdf

Consider using TextEncoder , which can easily encode/decode Strings and ArrayBuffers:考虑使用TextEncoder ,它可以轻松地对字符串和 ArrayBuffer 进行编码/解码:

const encoder = new TextEncoder(),
      decoder = new TextDecoder(),
      text = 'Hello',
      textEncoded = encoder.encode(text),
      textDecoded = decoder.decode(textEncoded);

console.log({ text, textDecoded, textEncoded });

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

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