Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

360
Views
Cómo usar estilos de fuente personalizados en jsPDF (React)

Tengo un proyecto en el que convierto algunos <svg> a pdf usando jsPDF y el complemento svg2pdf . Ahora tengo fuentes personalizadas funcionando. Aquí hay un codesandbox con mi problema: Reproduction Codesandbox .

Básicamente, utilicé fontconverter para convertir los archivos .ttf a base64 y exporté la función callAddFont :

 var callAddFont = function () { this.addFileToVFS("SourceSansPro-Regular-normal.ttf", SourceSansProRegular); this.addFileToVFS("SourceSansPro-Italic-normal.ttf", SourceSansProItalic); this.addFileToVFS("SourceSansPro-Bold-bold.ttf", SourceSansProBold); this.addFont("SourceSansPro-Regular-normal.ttf", "SourceSansPro", "normal"); this.addFont("SourceSansPro-Italic-normal.ttf", "SourceSansPro", "italic"); this.addFont("SourceSansPro-Bold-bold.ttf", "SourceSansPro", "bold"); }; export { callAddFont };

Luego creé algunos svg con diferentes font-styles :

 const svg = ` <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 595.28 841.89" > <text style="font-family: SourceSansPro; font-size: 11.5px;" x="10" y="20" fill="black">I am regular text</text> <text style="font-family: SourceSansPro; font-style: italic; font-size: 11.5px;" x="10" y="50" fill="black">I am italic text</text> <text style="font-family: SourceSansPro; font-style: bold; font-size: 11.5px;" x="10" y="90" fill="black">I am supposed to be BOLD & beautiful</text> </svg> `;

Al llamar al método doc.svg() , por alguna razón, los estilos de fuente normal y italic funcionan bien. Sin embargo, negrita no funciona .

Puedo llamar a doc.setFont("SourceSansPro", "bold"); , pero luego el texto normal también se pone en negrita, así que eso no es lo que quiero. Quiero que funcione con los estilos CSS en línea.

No entiendo por qué la cursiva funciona bien, pero la negrita no.

Cualquier ayuda es apreciada.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!