NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Microsoft.AspNetCore.Mvc;
using SMXServicesConsulting.DataModel.Models;
using System.Net.Http;
using System.Threading.Tasks;

namespace YourNamespace.Controllers
{
public class HomeController : Controller
{
private readonly IHttpClientFactory _httpClientFactory;

public HomeController(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}

public IActionResult Index()
{
return View();
}

[HttpPost]
public async Task<IActionResult> GeneratePdf([FromBody] CommissionMasterModelForHourlyEmployee model)
{
var client = _httpClientFactory.CreateClient();
var response = await client.PostAsJsonAsync("https://your-api-url/api/pdf/generate", model);

if (response.IsSuccessStatusCode)
{
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
return File(pdfBytes, "application/pdf", "Table.pdf");
}

return BadRequest("Error generating PDF");
}
}
}

@model SMXServicesConsulting.DataModel.Models.CommissionMasterModelForHourlyEmployee

@{
ViewData["Title"] = "SMX Services Consulting - Commissions of EO";
}

<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Commissions of EO</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="costosTable-outer p-2">
<div class="table-responsive">
<table id="getEmployeetbl" class="table table-striped getEmployeetbl-2" style="width:100%">
<thead>
<tr>
<th>S.No.</th>
<th>Customer</th>
<th>ITEM</th>
<th>Margen</th>
<th>Coef. 5%</th>
<th>Eber</th>
</tr>
</thead>
<tbody id="myTable">
@{
var srNo = 1;
}
@if (Model != null)
{
if (Model.CommissionModelListForHourlyEmployee != null && Model.CommissionModelListForHourlyEmployee.Any())
{
if (@Model.CommissionModelListForHourlyEmployee.Count() == 0)
{
<tr>
<td colspan="6">No Records Available</td>
</tr>
}
else
{
@foreach (var item in Model.CommissionModelListForHourlyEmployee)
{
<tr>
<td>@srNo</td>
<td>@item.Customer</td>
<td>@item.ITEM</td>
<td>@item.Margen</td>
<td>@item.Coeff5Percent</td>
<td>@item.Eber</td>
</tr>
srNo = srNo + 1;
}
}
}
}
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="GeneratePDFOfEber">Generate PDF</button>
</div>
</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#GeneratePDFOfEber").click(function () {
$.ajax({
url: '@Url.Action("GeneratePdf", "Home")',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(@Html.Raw(Json.Serialize(Model))),
success: function (response) {
var blob = new Blob([response], { type: 'application/pdf' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'Table.pdf';
link.click();
},
error: function (xhr, status, error) {
console.error('Error generating PDF:', error);
}
});
});
});
</script>

using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using SMXServicesConsulting.DataModel.Models;

namespace YourNamespace.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PdfController : ControllerBase
{
[HttpPost("generate")]
public IActionResult GeneratePdf([FromBody] CommissionMasterModelForHourlyEmployee model)
{
var memoryStream = new MemoryStream();

// Initialize PDF writer
var writer = new PdfWriter(memoryStream);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);

// Create a table with 6 columns
var table = new Table(6, true);

// Add header row
table.AddHeaderCell("S.No.");
table.AddHeaderCell("Customer");
table.AddHeaderCell("ITEM");
table.AddHeaderCell("Margen");
table.AddHeaderCell("Coef. 5%");
table.AddHeaderCell("Eber");

// Add data rows
if (model.CommissionModelListForHourlyEmployee != null)
{
int srNo = 1;
foreach (var item in model.CommissionModelListForHourlyEmployee)
{
table.AddCell(srNo.ToString());
table.AddCell(item.Customer);
table.AddCell(item.ITEM);
table.AddCell(item.Margen.ToString());
table.AddCell(item.Coeff5Percent.ToString());
table.AddCell(item.Eber.ToString());
srNo++;
}
}

document.Add(table);
document.Close();

// Return the PDF as a file download
var content = memoryStream.ToArray();
return File(content, "application/pdf", "Table.pdf");
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.