How to save pdf in proper encoding via nodejs

前端 未结 1 1135
滥情空心
滥情空心 2021-01-12 18:54

So I\'m trying to download a pdf file from a website with my script but the problem is that the file gets broken in the process and I\'m pretty sure it\'s because of wrong e

相关标签:
1条回答
  • 2021-01-12 19:42

    I know its very late but i seen your question today so i am answering it so that other can get help from this. You can add the encoding when you are trying to write the file i.e-:

    fs.writeFileSync("10111.pdf", body,'binary');
    

    As i set encoding format as binary here you can use which is right encoding format according to your requirenment if you are trying to download a pdf that you can set encoding as null.

    Hope this would help

    0 讨论(0)
提交回复
热议问题