Unicode charsets issue with AWS Lambda












8















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)










share|improve this question


















  • 1





    How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

    – cementblocks
    Nov 14 '18 at 18:02











  • Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

    – bwest
    Nov 14 '18 at 18:10













  • @cementblocks i am creating a stream using ejs and directly uploading the stream to S3

    – Deepak Mallah
    Nov 15 '18 at 9:53











  • @DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

    – Panagiotis Kanavos
    Nov 20 '18 at 8:40








  • 1





    @DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

    – Panagiotis Kanavos
    Nov 20 '18 at 8:42


















8















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)










share|improve this question


















  • 1





    How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

    – cementblocks
    Nov 14 '18 at 18:02











  • Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

    – bwest
    Nov 14 '18 at 18:10













  • @cementblocks i am creating a stream using ejs and directly uploading the stream to S3

    – Deepak Mallah
    Nov 15 '18 at 9:53











  • @DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

    – Panagiotis Kanavos
    Nov 20 '18 at 8:40








  • 1





    @DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

    – Panagiotis Kanavos
    Nov 20 '18 at 8:42
















8












8








8








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)










share|improve this question














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)







node.js amazon-web-services aws-lambda aws-sdk html-pdf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 17:26









Deepak MallahDeepak Mallah

1,64311324




1,64311324








  • 1





    How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

    – cementblocks
    Nov 14 '18 at 18:02











  • Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

    – bwest
    Nov 14 '18 at 18:10













  • @cementblocks i am creating a stream using ejs and directly uploading the stream to S3

    – Deepak Mallah
    Nov 15 '18 at 9:53











  • @DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

    – Panagiotis Kanavos
    Nov 20 '18 at 8:40








  • 1





    @DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

    – Panagiotis Kanavos
    Nov 20 '18 at 8:42
















  • 1





    How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

    – cementblocks
    Nov 14 '18 at 18:02











  • Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

    – bwest
    Nov 14 '18 at 18:10













  • @cementblocks i am creating a stream using ejs and directly uploading the stream to S3

    – Deepak Mallah
    Nov 15 '18 at 9:53











  • @DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

    – Panagiotis Kanavos
    Nov 20 '18 at 8:40








  • 1





    @DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

    – Panagiotis Kanavos
    Nov 20 '18 at 8:42










1




1





How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

– cementblocks
Nov 14 '18 at 18:02





How are you outputting the PDF? Upload to S3? return directly from lambda? How is the lambda invoked? Directly? Via apigateway? other Event?

– cementblocks
Nov 14 '18 at 18:02













Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

– bwest
Nov 14 '18 at 18:10







Is the string you are using for the file name returned from a lambda function? Try parsing it as JSON e.g. name = JSON.parse(filename) before using it.

– bwest
Nov 14 '18 at 18:10















@cementblocks i am creating a stream using ejs and directly uploading the stream to S3

– Deepak Mallah
Nov 15 '18 at 9:53





@cementblocks i am creating a stream using ejs and directly uploading the stream to S3

– Deepak Mallah
Nov 15 '18 at 9:53













@DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

– Panagiotis Kanavos
Nov 20 '18 at 8:40







@DeepakMallah square blocks typically appear when you use a font that doesn't include the character you want.

– Panagiotis Kanavos
Nov 20 '18 at 8:40






1




1





@DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

– Panagiotis Kanavos
Nov 20 '18 at 8:42







@DeepakMallah you are. Otherwise you wouldn't see any text. If you see text, you are using a font even if it's a default one

– Panagiotis Kanavos
Nov 20 '18 at 8:42














1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305710%2funicode-charsets-issue-with-aws-lambda%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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.






    share|improve this answer






























      0














      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.






      share|improve this answer




























        0












        0








        0







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 9:09

























        answered Nov 20 '18 at 16:07









        TaterheadTaterhead

        3,10621423




        3,10621423
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305710%2funicode-charsets-issue-with-aws-lambda%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown