Bullet points and alphabets are missing when converting html to pdf using jsPDF

huangapple go评论63阅读模式
英文:

Bullet points and alphabets are missing when converting html to pdf using jsPDF

问题

我尝试使用jsPDF将HTML转换为PDF。

我无法得到与原始HTML相同的PDF。
有序列表和无序列表的项目符号在PDF文件中丢失了。

HTML中的有序列表:

Bullet points and alphabets are missing when converting html to pdf using jsPDF

PDF中的有序列表:

Bullet points and alphabets are missing when converting html to pdf using jsPDF

HTML中的无序列表:

Bullet points and alphabets are missing when converting html to pdf using jsPDF

PDF中的无序列表:

Bullet points and alphabets are missing when converting html to pdf using jsPDF

请帮助我解决这个问题。

function BlazorDownloadFile(filename, text) {
  let parser = new DOMParser();
  let doc = parser.parseFromString(text, "text/html");

  console.log(doc.body);
  const element = doc.body;

  var opt = {
    margin: 1,
    filename: filename,
    html2canvas: { scale: 2 },
    jsPDF: { unit: "cm", format: "a4", orientation: "portrait" },
  };
  // 选择我们的发票渲染在其中的元素。
  html2pdf().set(opt).from(element).save();
}
英文:

I try to convert from html to pdf using jsPDF.

I could not get the pdf as the original html.
ordered list and unordered list bullet points are missing in the pdf file.

ordered-list-in-html

Bullet points and alphabets are missing when converting html to pdf using jsPDF

ordered-list-in-pdf

Bullet points and alphabets are missing when converting html to pdf using jsPDF

unordered-list-in-html

Bullet points and alphabets are missing when converting html to pdf using jsPDF

unordered-list-in-pdf

Bullet points and alphabets are missing when converting html to pdf using jsPDF

function BlazorDownloadFile(filename, text) {
  let parser = new DOMParser();
  let doc = parser.parseFromString(text, "text/html");

  console.log(doc.body);
  const element = doc.body;

  var opt = {
    margin: 1,
    filename: filename,
    html2canvas: { scale: 2 },
    jsPDF: { unit: "cm", format: "a4", orientation: "portrait" },
  };
  // Choose the element that our invoice is rendered in.
  html2pdf().set(opt).from(element).save();
}

Please help me to fix this issue.

答案1

得分: 1

这是一种用于在scss中实现项目符号的解决方法,您可以使用它来解决这个问题:

ul li {
  list-style-type: none;
  &::before {
    content: '• ';
    margin-left: -1em;
  }
}
英文:

Here is a workaround for bullet points in scss you can use to overcome this issue:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

 ul li { 
  list-style-type: none; 
  &amp;:before { 
    content: &#39;• &#39;; 
    margin-left: -1em; 
  }
 }

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年1月9日 01:57:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定