Replies: 1 comment
-
Hi, i had the same problem yesterday. It works like this. export async function exportPdf(html: string) {
const entry = "/api/export/";
return axios
.post(`/cb/api/2${entry}`, html, {
responseType: "blob",
headers: {
"Content-Type": "text/html",
"Content-Encoding": "UTF-8",
Accept: "application/pdf, application/octet-stream",
},
})
.then((res) => {
const pdfBlob = new Blob([res.data], { type: "application/pdf" });
const pdfUrl = URL.createObjectURL(pdfBlob);
// open in new tab
window.open(pdfUrl);
// or download it
const link = document.createElement("a");
link.href = pdfUrl;
link.setAttribute("download", "filename.pdf");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// clean up
URL.revokeObjectURL(pdfUrl);
});
} i just used my code and adjusted it to you sample. It had not tested this snipped of code, especially what you'd expect to return from the exportPdf function but you get the idea. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
The following code involves using a native Form along with a hidden Iframe as the target to invoke an API and retrieve a large PDF file. My question is whether there is a method to achieve the same functionality using Axios instead.
Beta Was this translation helpful? Give feedback.
All reactions