Image and Font is missing if I download it from server
Question
Hi, I meet an issue when I want to download the generated pdf from the server side.
Description
I write some scripts in server side to generate the pdf and send it back to UI as blob. Everything looks good locally. I can use postman to download the response as pdf. However when I deploy it to AWS, the image and font family are all missing. All the text are gone and shown as dots. The pdf either I get it by postman or UI is not working. It is said "Cannot extract the embedded font 'BZZZZZ+ Roboto-Regular". Some characters may not display or print correctly." Could you help me with that? Thank you.
Code sample
` const generatePDF = async (req, res) => { const { body: { some variable, } = {} } = req; try{ let doc = new PDFDocument({ size: "LETTER", margin: 18, compress:false }); let filename = "file"; filename = encodeURIComponent(filename) + ".pdf";
/* Some Sample Code below */ doc.registerFont('Roboto', './src/fonts/Roboto-Regular.ttf'); const lineHeight = 15; const headerToTop = 25; doc .image("./src/img/logo.png", 36, headerToTop, { width: 124, height: 13 }) .font('Roboto') .fontSize(7) .text("some text", 218, headerToTop, { align: "left" }) }) res.writeHead(200, { ...PDF_CONTENT_TYPE_HEADER, "Content-disposition": 'attachment; filename="' + filename + '"' }) doc.pipe(res); doc.end(); } catch(err) { return handleError(err, req, res, "Failed to generate PDF!"); } } `
Your environment
- pdfkit version: 0.10.0
- Node version: v10.13.0
- Browser version (if applicable):
- Operating System:
Source: foliojs/pdfkit