This is a migrated thread and some comments may be shown as answers.

Export to PDF

6 Answers 662 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 25 Nov 2015, 08:56 AM

Hi,

I'd like to export the grid to PDF, and need to add column headers on each page.

I was able to apply the page template (page header and footer), but couldn't add the column headers on the grid on each page..

Also, I'd like to change font size when it exports to PDF. how can I change the font size?

 

Thank you,

 

 

// Export handler
  $("#export").on("click", function () {
   var grid = $("#grid").data("kendoGrid");
   grid.hideColumn(3);
  grid.columns[0].width = "60px";
   grid.columns[1].width = "60px";
   grid.refresh();
   kendo.drawing.drawDOM("#grid", {
    forcePageBreak: ".page-break",
    paperSize: "Legal",
    landscape: true,
    margin: {
     left   : "2mm",
     top    : "30mm",
     right  : "2mm",
     bottom : "40mm"
    },
    template: $("#page-template").html()
   })
   .then(function (group) {
    kendo.drawing.pdf.saveAs(group, "CFCReport.pdf");
    var grid = $("#grid").data("kendoGrid");
    grid.showColumn(3);
   grid.refresh();
   }); 

6 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 26 Nov 2015, 01:34 PM
Hello Ryan,

Thank you for contacting us.

I would recommend you to examine the following help article which elaborates more on your requirement. Generally the topic demonstrates how to customize the pdf layout the way you prefer.

I hope this information helps.

Regards,
Kostadin
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ofer
Top achievements
Rank 1
answered on 19 Apr 2016, 07:51 PM

I have a issue with the page template:

When My code is this:

    function getPDF(selector) {
        kendo.drawing.drawDOM($(selector))
.then(function(group){
         kendo.drawing.pdf.saveAs(group, "Narrative.pdf",{
                paperSize: "Letter",
                margin: { left: "1cm", top: "1cm", right: "2cm", bottom: "1cm" }
            });
        });
      } it creates the PDF fine.

But when I change it, so I can add the page template later,

the code

     function getPDF(selector) {
        kendo.drawing.drawDOM($(selector, {
        paperSize: "A4",
        margin: { left: "0cm", top: "1cm", right: "0cm", bottom: "1cm" }
})).then(function (group) {
// Render the result as a PDF file
return kendo.drawing.exportPDF(group);
}).done(function (data) {
// Save the PDF file
kendo.saveAs({
dataURI: data,
fileName: "Narrative.pdf",
proxyURL: "http://demos.telerik.com/kendo-ui/service/export"
});
});
      }

does not create a PDF

can you tell me what I am missing?

0
Daniel
Telerik team
answered on 21 Apr 2016, 02:26 PM
Hello Ofer,

I created a simple demo which looks like yours and behaves as expected. You can test it here:
http://dojo.telerik.com/IsOgU

Let me know if I'm missing something.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Khanh
Top achievements
Rank 1
answered on 14 Sep 2018, 07:44 AM

Dear Admin,

I have an issue regarding to export pdf kendo grid with group header: Sort icon & menu context icon are too weirded in PDF file. Could you please give me some suggestions ? Thank you so much.

Steps to reproduce:

1. Create a group by, sort a column as the attached image.

 

2. Click export PDF

Actual result: Sort icon & menu context icon are too weirded in PDF file (please refer the attached image).

Expected result: The exported pdf file displays as well as data in kendo grid.

This is my code:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/grid/multicolumnheaders">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.3.911/styles/kendo.material.mobile.min.css" />
    <script src="https://kendo.cdn.telerik.com/2018.3.911/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2018.3.911/js/kendo.all.min.js"></script>
</head>
<body>
        <div id="example">
            <div id="grid"></div>
            <script>
                $(document).ready(function () {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
                            },
                            pageSize: 20
                        },
                        toolbar: ["pdf"],
                        pdf: {
                                fileName: 'abc.pdf',
                                allPages: true,
                                paperSize: 'auto',
                                margin: { top: "3cm", right: "1cm", bottom: "1cm", left: "1cm" },
                        },
                        height: 550,
                        groupable: true,
                        sortable: true,
                        resizable: true,
                        reorderable: true,
                        pageable: true,
                        columnMenu: true,
                        columns: [{
                            field: "CompanyName",
                            title: "Company Name",
                            width: 420
                        },
                        {
                          field: "Country",
                          title: "Country",
                          width: 200
                        },        
                        {
                          field: "City",
                          title: "City",
                          width: 200
                        },        
                        {
                          field: "Phone",
                          title: "Phone",
                          width: 200
                        },         
                   ]});
                });
            </script>
        </div>


</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0
Tsvetina
Telerik team
answered on 17 Sep 2018, 03:48 PM
Hello Khanh,

When the stylesheet and font files used in the page are hosted on a different domain (CDN in this case), you need to explicitly define the fonts, which should be loaded while exporting the Grid to PDF. In this case, you would need to define WebComponentsIcons.ttf, which contains the Kendo UI icons:
<script>
  kendo.pdf.defineFont({
  });
</script>

Here, you can see that icons load as expected in the exported document:
http://dojo.telerik.com/@tsveti/eLayACAv



Regards,
Tsvetina
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Khanh
Top achievements
Rank 1
answered on 18 Sep 2018, 05:20 AM
Thanks so much Tsvetina, it works fine for me.
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Ofer
Top achievements
Rank 1
Daniel
Telerik team
Khanh
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or