Question T12828
Visible to All Users

Unable to add custom font for Survey PDF

created 2 years ago

Hi Team,

I am trying to adding custom font for Survey PDF using demo - https://surveyjs.io/pdf-generator/examples/custom-font-families-in-pdf-form/angular#content-code. But after adding it, PDF is not getting downloaded, neither its showing any errors!

We need Calibri Font

Can you guide me on it!

Answers approved by surveyjs Support

created 2 years ago

Hello Santosh,
To register a custom font for PDF surveys, get a TTF font file and follow the Change Fonts guide.

I created the following Angular Code Sandbox demo for your reference: https://codesandbox.io/s/surveyjs-angular-forked-gi38hd?file=/src/app/components/custom-fonts/Calibri+Bold-normal.js.

JavaScript
import { font_bold } from "./custom-fonts/Calibri Bold-normal"; import { font_regular } from "./custom-fonts/Calibri Regular-normal"; DocController.addFont("calibri", font_regular, "normal"); DocController.addFont("calibri", font_bold, "bold"); let pdfWidth = !!surveyModel && surveyModel.pdfWidth ? surveyModel.pdfWidth : 210; let pdfHeight = !!surveyModel && surveyModel.pdfHeight ? surveyModel.pdfHeight : 297; let options = { fontSize: 14, margins: { left: 10, right: 10, top: 10, bot: 10 }, fontName: "calibri", format: [pdfWidth, pdfHeight] }; const surveyPDF = new SurveyPDF(json, options); ...

Note: the Calibri Bold-normal.js and Calibri Regular-normal.js contains the Calibri Regular and Bold font styles. You can find these files in the attached zip archive.

Let me know if you have any questions or require further assistance.

    Comments (2)

      Thanks a lot Jane! Its working now!

        You're welcome, Santosh.

        Please let us know if you have any questions or require further assistance.