2 using DinkToPdf.Contracts;
3 using Microsoft.AspNetCore.Mvc;
5 using PdfService.Utility;
6 using PdfService.Models;
7 namespace PdfService.Controllers
12 public class PdfController : ControllerBase
14 private IConverter _converter;
16 public PdfController(IConverter converter)
18 _converter = converter;
21 [Route("generatePDF")]
23 public ActionResult Get()
25 var globalSettings = new GlobalSettings
27 ColorMode = ColorMode.Color,
28 Orientation = Orientation.Portrait,
29 PaperSize = PaperKind.A4,
30 Margins = new MarginSettings { Top = 0, Left = 0, Right = 0 },
31 DocumentTitle = "PDF Report",
34 var objectSettings = new ObjectSettings
37 HtmlContent = TemplateGenerator.GetHTMLString(new Tweet[]{new Tweet("Test", "Good"), new Tweet("Test2", "Bad")}),
38 WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "bulma.min.css") }
41 var pdf = new HtmlToPdfDocument()
43 GlobalSettings = globalSettings,
44 Objects = { objectSettings }
47 var file = _converter.Convert(pdf);
48 return File(file, "application/pdf");