Getting Started with PDF Export
This guide demonstrates how to use the Kendo UI for jQuery Drawing Library and drawDOM to export page content to a PDF file.
After the completion of this guide, you will achieve the following result:
1. Draw the Scene
Use the Drawing API to generate a drawing group from the current DOM content.
When you export HTML content with drawDOM, the PDF output preserves common document structures such as ordered and unordered lists, including bullet points.
kendo.drawing.drawDOM("#container");
2. Configure the PDF Options
Define the PDF options in a variable and set values such as margins, landscape mode, and paper size:
var pdfOptions = {
margin: "2px",
paperSize: "A3",
landscape: true,
multiPage: true
};
3. Export the Scene to PDF
Pass the pdfOptions object to drawDOM, and then chain the saveAs call to export the generated scene to a PDF file:
var pdfOptions = {
margin: "2px",
paperSize: "A3",
landscape: true,
multiPage: true
};
kendo.drawing.drawDOM("#container", pdfOptions).then(function(group){
kendo.drawing.pdf.saveAs(group, "filename.pdf");
});
(Optional) 4. Convert the PDF to a Data URI or Blob
You can convert the generated PDF to Data URI or a Blob. By doing so you can attach the file to a form that can be submitted later on.
kendo.drawing.pdf.toBlob(group, function(blob){
// You can now upload it to a server.
// This form simulates an <input type="file" name="pdfFile" />.
var form = new FormData();
form.append("pdfFile", blob);
console.info(form.get("pdfFile"));
// Post the content to the server which can save it.
// var xhr = new XMLHttpRequest();
// xhr.open("POST", "/posturl", true);
// xhr.send(form);
});
// Alternatively, you can get it as a data URL.
kendo.drawing.pdf.toDataURL(group, function(dataURL){ ... });
Next Steps
- PDF Options
- Customizing the Appearance
- Multi-Page Content
- Drawing Library Overview
- Drawing HTML Elements Overview
- Saving Files