2 using DinkToPdf.Contracts;
3 using Microsoft.AspNetCore.Mvc;
6 namespace PdfService.Controllers
11 public class PdfController : ControllerBase
13 private IConverter _converter;
15 public PdfController(IConverter converter)
17 _converter = converter;
20 [Route("generatePDF")]
22 public ActionResult Get()
24 var globalSettings = new GlobalSettings
26 ColorMode = ColorMode.Color,
27 Orientation = Orientation.Portrait,
28 PaperSize = PaperKind.A4,
29 Margins = new MarginSettings { Top = 10 },
30 DocumentTitle = "PDF Report",
33 var objectSettings = new ObjectSettings
37 WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
38 HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
39 FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
42 var pdf = new HtmlToPdfDocument()
44 GlobalSettings = globalSettings,
45 Objects = { objectSettings }
48 var file = _converter.Convert(pdf);
49 return File(file, "application/pdf");