alixaxel / chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions
MIT License
3.2k stars 292 forks source link

Chinese/Japanese/Korean characters are not displayed #245

Open GuyMoreh opened 2 years ago

GuyMoreh commented 2 years ago

Hey,

Thanks for the great library!!

I'm using this library to generate pdfs, but non-english characters are displayed as blocks.

I have tried to follow this issue (https://github.com/alixaxel/chrome-aws-lambda/issues/108) but the results are the same...

Can anyone please provide a guide or something??

Versions:

Thanks!

Curryking100k commented 2 years ago

module.exports.handler = async (event, context, callback) => { let result = null; let browser = null; let bodyContent = event.data; let headerTemplate = event.headerTemplate || '' let footerTemplate = event.footerTemplate || '' try { await chromium.font('https://s3.ap-northeast-2.amazonaws.com/fonts/webfont.ttf') <--here console.log(event) browser = await chromium.puppeteer.launch({ args: chromium.args, defaultViewport: chromium.defaultViewport, executablePath: await chromium.executablePath, headless: chromium.headless, ignoreHTTPSErrors: true, });

junguksim commented 1 year ago

Hello. I solved this by following @Curryking100k 's code. Add this part.

await chromium.font('https://s3.ap-northeast-2.amazonaws.com/fonts/webfont.ttf') // Add font for chromium

For the font link, I suggest you to use Noto Sans SC font. I tried normal Noto Sans font but it didn't work for me.

So I downloaded NotoSansSC-Regular.ttf, and uploaded to my S3 bucket, and then used the S3 link. It worked now. (Also supporting Japanese)

https://fonts.google.com/noto/specimen/Noto+Sans+SC