Notes
![]() ![]() Notes - notes.io |
using PdfSharp.Pdf;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.IO;
using System.Threading.Tasks;
public class CommissionController : Controller
{
private readonly IWebHostEnvironment _environment;
public CommissionController(IWebHostEnvironment environment)
{
_environment = environment;
}
[HttpPost]
public async Task<IActionResult> GeneratePdfOfEber()
{
try
{
// Create a new PDF document
Document document = new Document();
Section section = document.AddSection();
section.PageSetup.LeftMargin = Unit.FromCentimeter(1.1);
// Image path
string logoPath = Path.Combine(_environment.WebRootPath, "images", "logo_white.png");
if (System.IO.File.Exists(logoPath))
{
try
{
// Ensure that the image file is accessible and not locked
using (var fileStream = new FileStream(logoPath, FileMode.Open, FileAccess.Read))
{
var logo = section.Headers.Primary.AddImage(fileStream);
logo.Width = "4cm";
logo.LockAspectRatio = true;
logo.Top = ShapePosition.Top;
logo.Left = ShapePosition.Left;
logo.WrapFormat.Style = WrapStyle.Through;
}
}
catch (Exception ex)
{
// Handle specific image loading issues
section.Headers.Primary.AddParagraph("Error loading image: " + ex.Message)
.Format.Font.Color = Colors.Red;
}
}
else
{
// Fallback or error handling
section.Headers.Primary.AddParagraph("Logo image not found.")
.Format.Font.Color = Colors.Red;
}
// Title
var title = section.AddParagraph("Commissions Report");
title.Format.Font.Size = 16;
title.Format.Font.Bold = true;
title.Format.SpaceAfter = "1cm";
title.Format.Alignment = ParagraphAlignment.Center;
// Adding table
var table = section.AddTable();
table.Borders.Width = 0.5;
table.Borders.Color = Colors.Black;
table.AddColumn("5cm");
table.AddColumn("5cm");
table.AddColumn("3cm");
table.AddColumn("3cm");
table.AddColumn("3cm");
var row = table.AddRow();
row.Shading.Color = Colors.CornflowerBlue;
row.HeadingFormat = true;
row.Format.Font.Bold = true;
row.Format.Font.Size = 11;
row.Cells[0].AddParagraph("Customer");
row.Cells[1].AddParagraph("ITEM");
row.Cells[2].AddParagraph("Margen");
row.Cells[3].AddParagraph("Coef. 5%");
row.Cells[4].AddParagraph("Eber");
// Simulated data population
for (int i = 0; i < 10; i++)
{
row = table.AddRow();
row.Cells[0].AddParagraph($"Customer {i}");
row.Cells[1].AddParagraph($"Item {i}");
row.Cells[2].AddParagraph($"{1000 + i}");
row.Cells[3].AddParagraph($"{5 + i}");
row.Cells[4].AddParagraph($"{50 + i}");
}
// Rendering the document
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false)
{
Document = document
};
pdfRenderer.RenderDocument();
// Save the document to a stream
using (var memoryStream = new MemoryStream())
{
pdfRenderer.PdfDocument.Save(memoryStream, false);
string fileName = "CommissionsReport.pdf";
return File(memoryStream.ToArray(), "application/pdf", fileName);
}
}
catch (Exception ex)
{
// Handle exceptions as necessary
throw;
}
}
}
![]() |
Notes is a web-based application for online 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 14 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