--- /dev/null
+using DinkToPdf;
+using DinkToPdf.Contracts;
+using Microsoft.AspNetCore.Mvc;
+using System.IO;
+
+namespace PdfService.Controllers
+{
+
+
+ [ApiController]
+ public class PdfController : ControllerBase
+ {
+ private IConverter _converter;
+
+ public PdfController(IConverter converter)
+ {
+ _converter = converter;
+ }
+ // GET /generatePDF
+ [Route("generatePDF")]
+ [HttpGet]
+ public ActionResult Get()
+ {
+ var globalSettings = new GlobalSettings
+ {
+ ColorMode = ColorMode.Color,
+ Orientation = Orientation.Portrait,
+ PaperSize = PaperKind.A4,
+ Margins = new MarginSettings { Top = 10 },
+ DocumentTitle = "PDF Report",
+ };
+
+ var objectSettings = new ObjectSettings
+ {
+ PagesCount = true,
+ HtmlContent = "test",
+ WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
+ HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
+ FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
+ };
+
+ var pdf = new HtmlToPdfDocument()
+ {
+ GlobalSettings = globalSettings,
+ Objects = { objectSettings }
+ };
+
+ var file = _converter.Convert(pdf);
+ return File(file, "application/pdf");
+ }
+
+ }
+}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-
-namespace PdfService.Controllers
-{
- [Route("api/[controller]")]
- [ApiController]
- public class ValuesController : ControllerBase
- {
- // GET api/values
- [HttpGet]
- public ActionResult<IEnumerable<string>> Get()
- {
- return new string[] { "value1", "value2" };
- }
-
- // GET api/values/5
- [HttpGet("{id}")]
- public ActionResult<string> Get(int id)
- {
- return "value";
- }
-
- // POST api/values
- [HttpPost]
- public void Post([FromBody] string value)
- {
- }
-
- // PUT api/values/5
- [HttpPut("{id}")]
- public void Put(int id, [FromBody] string value)
- {
- }
-
- // DELETE api/values/5
- [HttpDelete("{id}")]
- public void Delete(int id)
- {
- }
- }
-}
RUN dotnet publish -c Release -o out
# Build runtime image
-FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime-alpine
+FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
+
+# copy pdf library
+# COPY libwkhtmltox.* ./
+# install additional libaries
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ zlib1g \
+ fontconfig \
+ libfreetype6 \
+ libx11-6 \
+ libxext6 \
+ libxrender1 \
+ && curl -o /usr/lib/libwkhtmltox.so \
+ --location \
+ https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so
+
ENTRYPOINT ["dotnet", "PdfService.dll"]
\ No newline at end of file
--- /dev/null
+
+namespace PdfService.Models
+{
+ // represents the data got from sentiment analysis.
+ // TODO: adapt to real data from sentiment analysis
+ public class Tweet
+ {
+ public string Name { get; set; }
+ public string Sentiment { get; set; }
+ }
+}
\ No newline at end of file
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="DinkToPdf" Version="1.0.8" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0-preview3-35497" PrivateAssets="All" />
</ItemGroup>
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
+using DinkToPdf;
+using DinkToPdf.Contracts;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
+using PdfService.Utility;
namespace PdfService
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+
+ services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
# PDF Service
-Provides an API interface to generate PDF reports for given inputs
-`POST`: `/generatePdf/` (TODO)
+Provides an API interface to generate PDF reports for given tweets and their sentiment analysis result.
+`POST`: `/generatePDF/` (TODO)
-# run with docker
+## run with docker
-`docker build -t pdfservice .` if no local image is available
-`docker run -p YOUR_PORT:80 pdfservice:latest`
+- (if no local image is available) `docker build -t pdfservice .`
+- `docker run -p YOUR_PORT:80 pdfservice:latest`
-# run local
-## requirements
+## run local
+### requirements
- .net core 2.2
-## commands
+### commands
- `dotnet run`
\ No newline at end of file