|
@@ -1,4 +1,6 @@
|
|
|
using Azure.Cosmos;
|
|
|
+using DinkToPdf;
|
|
|
+using DinkToPdf.Contracts;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
@@ -7,6 +9,7 @@ using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
@@ -37,10 +40,10 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
private readonly Option _option;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly AzureRedisFactory _azureRedis;
|
|
|
-
|
|
|
+ private readonly IConverter _converter;
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
- public StudyController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
+ public StudyController(IConverter converter,CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
|
|
|
{
|
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
@@ -52,6 +55,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
_azureStorage = azureStorage;
|
|
|
_azureRedis = azureRedis;
|
|
|
_configuration = configuration;
|
|
|
+ _converter = converter;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 保存研修信息
|
|
@@ -784,5 +788,79 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
await Task.WhenAll(tasks);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ [HttpPost("gen-pdf")]
|
|
|
+ //[Authorize(Roles = Constant.Role_Root)]
|
|
|
+ public IActionResult GenPdf(JsonElement json)
|
|
|
+ {
|
|
|
+ //https://article.itxueyuan.com/JAxOnG
|
|
|
+ //http://t.zoukankan.com/hsiang-p-14608694.html
|
|
|
+ //https://github.com/rdvojmoc/DinkToPdf
|
|
|
+ //https://blog.csdn.net/u011966339/article/details/114964016?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-114964016-blog-118609642.pc_relevant_antiscanv2&spm=1001.2101.3001.4242.1&utm_relevant_index=3
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ GlobalSettings globalSettings = new GlobalSettings();
|
|
|
+ globalSettings.ColorMode = ColorMode.Color;
|
|
|
+ globalSettings.Orientation = Orientation.Portrait;
|
|
|
+ globalSettings.PaperSize = PaperKind.A4;
|
|
|
+ globalSettings.Margins = new MarginSettings { Top = 25, Bottom = 25 };
|
|
|
+ globalSettings.Out = @"E:\pdf\test.pdf";
|
|
|
+ ObjectSettings objectSettings = new ObjectSettings();
|
|
|
+ objectSettings.PagesCount = true;
|
|
|
+ objectSettings.HtmlContent = Constant.html;
|
|
|
+ WebSettings webSettings = new WebSettings();
|
|
|
+ webSettings.DefaultEncoding = "utf-8";
|
|
|
+ HeaderSettings headerSettings = new HeaderSettings();
|
|
|
+ headerSettings.FontSize = 15;
|
|
|
+ headerSettings.FontName = "fangsong";
|
|
|
+ headerSettings.Right = "";
|
|
|
+ // headerSettings.Line = true;
|
|
|
+ FooterSettings footerSettings = new FooterSettings();
|
|
|
+ footerSettings.FontSize = 12;
|
|
|
+ footerSettings.FontName = "Ariel";
|
|
|
+ footerSettings.Center = "校本研修活动完成情况([page]/[toPage])页";
|
|
|
+ // footerSettings.Line = true;
|
|
|
+ objectSettings.HeaderSettings = headerSettings;
|
|
|
+ objectSettings.FooterSettings = footerSettings;
|
|
|
+ objectSettings.WebSettings = webSettings;
|
|
|
+ HtmlToPdfDocument htmlToPdfDocument = new HtmlToPdfDocument()
|
|
|
+ {
|
|
|
+ GlobalSettings = globalSettings,
|
|
|
+ Objects = { objectSettings },
|
|
|
+ };
|
|
|
+ var a = _converter.Convert(htmlToPdfDocument);
|
|
|
+ MemoryStream m = new MemoryStream(a);
|
|
|
+ /* FileStream fs = new FileStream("F:\\1111111111111\\SimplePdf1.pdf", FileMode.Create, FileAccess.Write, FileShare.Read);
|
|
|
+ m.WriteTo(fs);
|
|
|
+ m.Close();
|
|
|
+ fs.Close();*/
|
|
|
+
|
|
|
+ //var doc = new HtmlToPdfDocument()
|
|
|
+ //{
|
|
|
+ // GlobalSettings = {
|
|
|
+ // ColorMode = ColorMode.Color,
|
|
|
+ // Orientation = Orientation.Portrait,
|
|
|
+ // PaperSize = PaperKind.A4,
|
|
|
+ // Margins = new MarginSettings() { Top = 10 },
|
|
|
+ // Out = @"F:\test.pdf",
|
|
|
+ // },
|
|
|
+ // Objects = {
|
|
|
+ // new ObjectSettings()
|
|
|
+ // {
|
|
|
+ // Page = "https://zhidao.baidu.com/question/175696719173618004.html",
|
|
|
+ // },
|
|
|
+ // }
|
|
|
+ //};
|
|
|
+ //_converter.Convert(doc);
|
|
|
+ return Ok();
|
|
|
+ // return Ok(File(a, "application/octet-stream", "SimplePdf.pdf"));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return BadRequest(new { ex = ex.StackTrace, exmsg = ex.Message });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|