Skip to content

How to use Browserless PDF API from expressjs? #4140

Closed Answered by perevezencev
perevezencev asked this question in Q&A
Discussion options

You must be logged in to vote

I needed to add the responseType: "arraybuffer" to the axios.post config object:

app.get("/api/pdf", async (request, response) => {
    try {
        const { data } = await axios.post(
            "http://localhost:3001/pdf",
            {
                url: "https://www.google.com/",
            },
            {
                responseType: "arraybuffer",
            },
        )

        response.setHeader("content-type", "application/pdf")
        response.contentType("application/pdf")
        response.send(Buffer.from(data, "binary"))
    } catch (error) {
        console.log(error.message)
    }
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by joelgriffith
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant