]> git.somenet.org - pub/jan/aic18.git/blob - PdfService/Controllers/PdfController.cs
Issue #3:
[pub/jan/aic18.git] / PdfService / Controllers / PdfController.cs
1 using DinkToPdf;
2 using DinkToPdf.Contracts;
3 using Microsoft.AspNetCore.Mvc;
4 using System.IO;
5
6 namespace PdfService.Controllers
7 {
8
9     
10     [ApiController]
11     public class PdfController : ControllerBase
12     {
13         private IConverter _converter;
14
15         public PdfController(IConverter converter)
16         {
17             _converter = converter;
18         }
19         // GET /generatePDF
20         [Route("generatePDF")]
21         [HttpGet]
22         public ActionResult Get()
23         {
24             var globalSettings = new GlobalSettings
25             {
26                 ColorMode = ColorMode.Color,
27                 Orientation = Orientation.Portrait,
28                 PaperSize = PaperKind.A4,
29                 Margins = new MarginSettings { Top = 10 },
30                 DocumentTitle = "PDF Report",
31             };
32  
33             var objectSettings = new ObjectSettings
34             {
35                 PagesCount = true,
36                 HtmlContent = "test",
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" }
40             };
41  
42             var pdf = new HtmlToPdfDocument()
43             {
44                 GlobalSettings = globalSettings,
45                 Objects = { objectSettings }
46             };
47  
48             var file = _converter.Convert(pdf);
49             return File(file, "application/pdf");
50         }
51
52     }
53 }