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

Bar code in pdf header

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 20 Jun 2019, 06:07 PM

Is there an example of how to render a bar code widget in a pdf export header using a kendo template? I'm using MVC/Razor.

 

This does not work

 

<script type="x/kendo-template" id="page-template">
    <div class="pdf-page-template">
        <div class="header">
            <h1>My Order</h1>

    <div>@(Html.Kendo().Barcode().Name("gudbrands").Value(Model.OrderNumber).Encoding(BarcodeSymbology.Code39).Width(280).Height(100))</div>
                <div><strong>Order Number</strong> @Model.Header.OrderNumber
        </div>
    </div>
</script>

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 24 Jun 2019, 02:11 PM
Hello Marc,

Have you considered adding the barcode above the grid and export the parent element of both widgets?

Same approach is shown in the following demo:


Since adding the widget to the pdf template will not work as expected.


Regards,
Georgi
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
Marc
Top achievements
Rank 1
answered on 24 Jun 2019, 03:36 PM
The bar code is only relevant to a hard copy printed from the pdf so I'd prefer not to have it on the web page. Is there no way to include the code into the template?
0
Georgi
Telerik team
answered on 26 Jun 2019, 01:56 PM
Hello Marc,

You could append the barcode when the grid is exported.

e.g.

var grid1 = $('#grid').data('kendoGrid');
 
var progress = $.Deferred();
 
grid1._drawPDF(progress)
  .then(function(firstGrid) {
 
  var barcode = $('<span></span>')
  .appendTo($('#barcodeContainer'))
  .kendoBarcode({
    value: "2346722",
    type: "ean8",
    width: 280,
    height: 100
  }).data('kendoBarcode');
 
 
kendo.drawing.drawDOM($("#barcodeContainer"))
    .then(function(barcodepdf){
      debugger
    barcodepdf.children.forEach(function(x){
      firstGrid.children.unshift(x);
    })
 
    return kendo.drawing.exportPDF(firstGrid, { multiPage: true });
 
  }).done(function(dataURI) {
    kendo.saveAs({
      dataURI: dataURI,
      fileName: "test.pdf"
    });
    progress.resolve();
    $('#barcodeContainer').empty()
  })

Below you will find a small sample which demonstrates the above approach:


I hope this helps.


Regards,
Georgi
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.
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Marc
Top achievements
Rank 1
Share this question
or