Pdf Exporting With an Image

Hi guys, first of all let me say that the new Grid control is amazing. 

I am trying to use the Pdf export with an image in the header 


For the moment i want to use the same image  every time that the user export the report.

So i set the complete base64 image value in the header contents 

But i get an error , like this 

TypeError: Cannot read property 'toString' of undefined
    at e.save (split-button.js:294)
    at t.e.saveItems (split-button.js:294)
    at t.e.save (split-button.js:294)
    at t.save (split-button.js:294)
    at e.doSaveObject (split-button.js:294)
    at e.saveIndirectObject (split-button.js:294)
    at e.saveObjects (split-button.js:294)
    at e.save (split-button.js:294)
    at t.docSave (split-button.js:294)
    at t.e.save (split-button.js:294)

Can you provide me a real example about use images ???

I think it is going to be useful for another users to.
var exportProperties = {
    header: {
        fromTop: 0,
        height: 130,
        contents: [
            {
                type: 'Image',
                src: image,
                position: { x: 435, y: 10 },
                size: { height: 100, width: 250 },
            }
        ]
    }
}     


1 Reply

RS Renjith Singh Rajendran Syncfusion Team May 31, 2018 02:54 PM UTC

Hi Redecon, 

Thanks for contacting Syncfusion support. 

Based on your requirement we have prepared a sample to display an image in the header of the exported PDF file. Please download the sample from the link below, 

To add images to the pdf in the pdfExportProperties, use .jpg images with Base64 string in the pdfExportProperties. Please refer the code example below, 

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).AllowPdfExport().ToolbarClick("toolbarClick") 
        .Columns(col => 
        { 
            ... 
       }).Toolbar(new List<string>() { "PdfExport" }).Render() 
 
<script type="text/javascript"> 
    function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
        if (args['item'].id === 'Grid_pdfexport') { 
            var pdfExportProperties = { 
                header: { 
                    fromTop: 0, 
                    height: 130, 
                    contents: [ 
                        { 
                            type: 'Image', 
                            src: image              //give image as Base64 string 
                            position: { x: 435, y: 10 }, 
                            size: { height: 100, width: 250 }, 
                        } 
                    ] 
                } 
            }; 
            gridObj.pdfExport(pdfExportProperties); 
        } 
    } 
</script> 

We are not able to get that script error during exporting. If you still face that issue during exporting. Please get back to us with the following details, 

  1. Share exact scenario when your are facing this error.
  2. Share full Grid code example.
  3. Essential JS2 version details.
  4. Share the Base64 string you provide as value for src.

The provided information will help us to analyze the issue and provide you the response as early as possible. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon