Deepak Mallah
Deepak Mallah

Reputation: 4076

Unicode charsets issue with AWS Lambda

I am using AWS Lambda for generating pdf where html-pdf is the npm package. everything works flawless but the problem is with Hindi character. the characters appear gibberish and understandable something like as shown in attached image.enter image description here

Packages used

  1. html-pdf
  2. ejs

Things i tried:

i used same nodejs based code on my local machine and it was working as expected. but not working on Lambda (nodejs v6.10/8.10)

Upvotes: 10

Views: 3023

Answers (1)

Taterhead
Taterhead

Reputation: 5951

By default, Lambda does not output in binary. It base64 encodes all of your output.

If your PDF is served back via the API Gateway, you can reverse this with a change in the API Gateway in order to get binary with the following steps below the first image:

enter image description here

  1. Go to the corresponding API Gateway for your Lambda function (mine was Generate Calendar)
  2. Select Settings
  3. In the Binary Media Types enter */*
  4. Click the blue Save Changes button.

Then re-deploy the API. See following image and steps:

enter image description here

  1. Click Resources.
  2. Under the Action button, select Deploy API
  3. Under deployment stage, select Prod
  4. Then click blue Deploy button,

Here is a AWS forum post with a similar PDF problem to yours. Hope this helps.

Upvotes: 1

Related Questions