I'm using blazor server and I need to export a grid in pdf or excel or directly print it where I used your suggestion to add the barcode in a Template
<GridColumn TextAlign="TextAlign.Center">
<Template>
@{
var magazzino = (context as RiassuntoMagDTO);
//<div class="image">
<SfBarcodeGenerator Height="80" Type="@BarcodeType.Code128" Value=@(magazzino.barcode)>
<BarcodeGeneratorDisplayText Text="@(magazzino.barcode)"></BarcodeGeneratorDisplayText>
</SfBarcodeGenerator>
//</div>
}
</Template>
</GridColumn>
If I print or export in pdf or excel the barcode is not showed
Thanks
Hi Walter,
Greetings from Syncfusion support.
We are currently checking the feasibility of your requirement. We will update further details within two business days on or before (01.06.2022). Until then we appreciate your patience.
Regards,
Monisha
Hi Walter,
Thanks for the patience.
We have analyzed your query and currently, we do not have support to export the Grid Data to Pdf document along with the Barcode component. But we can achieve this requirement of exporting the Grid data with Barcode in it using external methods (i.e.) without using Grid’s built-in PdfExport method. While achieving this requirement using external actions, all actions need to be handled externally only.
So kindly confirm whether it is fine for you to achieve your requirement using the Syncfusion Pdf document externally without a built-in method. Based on your confirmation we will prepare and update you on the solution.
Regards,
Vignesh Natarajan
Hello Vignesh
thanks for your reply
yes, for me it's the same if it's possible to create a pdf with the grid content and relative barcode not using the built-in method
It would be great If you can lead me to the solution.
Thanks
Best Regards
Hi Walter,
Greetings from Syncfusion support.
Currently we are preparing sample at our end and we will update further details within two business days on or before (06.06.2022). Until then we appreciate your patience.
Regards,
Monisha
Hi Walter,
Thanks for the patience.
We have prepared an sample as per your requirement to export the barcode. Here we have drawn barcode and exported to grid by using Javascript function. Kindly check the attached code snippet and sample for your reference.
<SfGrid DataSource="@Orders" ID="Grid" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" @ref="DefaultGrid" AllowPaging="true"> <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> ... </SfGrid>
@code {
public List<Order> Orders { get; set; } public SfGrid<Order> DefaultGrid; //Create a new PDF document static Syncfusion.Pdf.PdfDocument pdfDocument = new Syncfusion.Pdf.PdfDocument(); //Add a page static Syncfusion.Pdf.PdfPage page = pdfDocument.Pages.Add();
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) {
if (args.Item.Id == "Grid_pdfexport") //Id is combination of Grid's ID and itemname { PdfGrid pdfGrid = new PdfGrid(); //Add columns to PdfGrid pdfGrid.Columns.Add(3); //Add rows to PdfGrid for (int i = 0; i < pdfGrid.Columns.Count; i++) { PdfGridRow row = pdfGrid.Rows.Add(); row.Cells[2].Value = Orders[i].OrderID.ToString();
} //Set height pdfGrid.Rows[0].Height = 70;
pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout;
//Draw grid to the page of PDF document pdfGrid.Draw(page,new Syncfusion.Drawing.PointF(10, 10));
MemoryStream ms = new MemoryStream(); //Save the document pdfDocument.Save(ms);
await Runtime.InvokeVoidAsync("exportSave", new object[] { "export.pdf", Convert.ToBase64String(ms.ToArray()) });
}
} private static void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args) { if (args.RowIndex == 0 && args.CellIndex == 1 && !args.IsHeaderRow) { //Drawing Code39 barcode PdfCode39Barcode barcode = new PdfCode39Barcode();
//Setting height of the barcode barcode.BarHeight = 45; barcode.Text = "CODE39$";
//Draw barcode with respect to grid cell bounds barcode.Draw(page, new Syncfusion.Drawing.PointF(args.Bounds.X + 5, args.Bounds.Y + 5)); } }
} |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid1165188702.zip
Kindly get back to us if you have further queries.
Regards,
Monisha
thanks for your sample
I tried to change it because I need to generate the Pdf where the barcode is created for every Orders.OrderID value but as you can see if I "draw" it in the pdf, the barcodes of the second page will be drawed over the ones in the first page
How can I solve this problem ?
Hi Walter,
Thanks for contacting Syncfusion support.
We have modified the sample as per your requirement to draw the barcodes inside
the cell on a multi-page pdf grid. We have attached code snippet and sample for
your reference. Please check the attached sample at your end.
<SfGrid DataSource="@Orders" ID="Grid" Toolbar="@(new List<string>() { "PdfExport" })" AllowPdfExport="true" @ref="DefaultGrid" AllowPaging="true"> <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> <GridColumns> … </GridColumns> </SfGrid>
@code { public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) {
if (args.Item.Id == "Grid_pdfexport") //Id is combination of Grid's ID and itemname { pdfDocument.Pages.PageAdded += Pages_PageAdded; PdfGrid pdfGrid = new PdfGrid(); //Add columns to PdfGrid ...
} private static void Pages_PageAdded(object sender, PageAddedEventArgs args) { page = args.Page; }
|
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridSample595653234
Kindly get back to us if you gave further queries.
Regards,
Monisha
Thanks it works perfectly
Hi Walter,
Welcome.
Kindly get back to us if you have further queries. As always we will be happy to help you.
Regards,
Monisha