-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSaveToPdfController.cs
40 lines (33 loc) · 1.02 KB
/
SaveToPdfController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Api2PdfLibrary;
using Newtonsoft.Json;
namespace AspNet.Core.Mvc.Controllers
{
public class SaveToPdfController : Controller
{
[HttpPost]
public IActionResult Handle([FromBody]PdfModel model)
{
//Use NUGET
//install-package api2pdf
var a2pClient = new Api2Pdf("YOURAPIKEY");
var pdfUrl = a2pClient.WkHtmlToPdf.FromHtml(model.Content).Pdf;
var result = new
{
pdfUrl = pdfUrl
};
//Uncomment and modify if CORS is required
//this.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
return Content(JsonConvert.SerializeObject(result), "application/json");
}
public class PdfModel
{
public string Content { get; set; }
}
}
}