ShapeGenerator.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using DocumentFormat.OpenXml.Drawing;
  2. using DocumentFormat.OpenXml.Packaging;
  3. using DocumentFormat.OpenXml.Presentation;
  4. using HiTeachCC.Model.PowerPoint;
  5. using HiTeachCC.Service.Core.Implement;
  6. using HiTeachCC.Service.Core.Interface;
  7. using HiTeachCC.Service.PowerPoint.Interface;
  8. using Microsoft.AspNetCore.Http;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. using System.Xml.Linq;
  16. using System.Xml.XPath;
  17. using TEAMModelOS.SDK.Context.Constant;
  18. using TEAMModelOS.SDK.Context.Constant.Common;
  19. using TEAMModelOS.SDK.Context.Exception;
  20. using TEAMModelOS.SDK.Helper.Common.JsonHelper;
  21. using TEAMModelOS.SDK.Helper.Common.StringHelper;
  22. using TEAMModelOS.SDK.Helper.Security.ShaHash;
  23. using TEAMModelOS.SDK.Module.AzureBlob.Container;
  24. using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
  25. using ColorMap = DocumentFormat.OpenXml.Presentation.ColorMap;
  26. namespace HiTeachCC.Service.PowerPoint.Implement
  27. {
  28. public class ShapeGenerator :BaseService, IShapeGenerator
  29. {
  30. bool isDone = false;
  31. List<object> MsgQueue = new List<object>();
  32. // dynamic slideLayoutClrOvride;
  33. XmlDocument themeContent;
  34. int chartID = 0;
  35. int _order = 1;
  36. int titleFontSize = 42;
  37. int bodyFontSize = 20;
  38. int otherFontSize = 16;
  39. bool isSlideMode = false;
  40. Dictionary<string, object> styleTable = new Dictionary<string, object>();
  41. const double inchpixel = 96.00, inchpt = 72.00, pxBase = 914400.00, ptBase = 12700;
  42. const double rotBase = 60000.00;
  43. private readonly IAzureBlobDBRepository azureBlobDBRepository;
  44. public ShapeGenerator(IAzureBlobDBRepository _azureBlobDBRepository)
  45. {
  46. azureBlobDBRepository = _azureBlobDBRepository;
  47. }
  48. public async Task<Dictionary<string, object>> LoadPresentation(IFormFile file)
  49. {
  50. Dictionary<string, object> resdict = new Dictionary<string, object>();
  51. if (FileType.GetExtention(file.FileName).ToLower().Equals("pptx"))
  52. {
  53. ConvertPPTX(file, resdict);
  54. return resdict;
  55. }
  56. else if (FileType.GetExtention(file.FileName).ToLower().Equals("pdf"))
  57. {
  58. // await ProcessPDF(file, resdict);
  59. return resdict;
  60. }
  61. else
  62. {
  63. throw new BizException(500, "file type does not support!");
  64. }
  65. }
  66. public Dictionary<string, object> ConvertPPTX(IFormFile file, Dictionary<string, object> resdict) {
  67. string shaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
  68. using (PresentationDocument presentationDocument = PresentationDocument.Open(file.OpenReadStream(), false))
  69. {
  70. if (presentationDocument == null)
  71. {
  72. throw new ArgumentNullException("presentationDocument");
  73. }
  74. XDocument xdoc = presentationDocument.ToFlatOpcDocument();
  75. var rslt_ary = ProcessPPTX(xdoc);
  76. return null;
  77. }
  78. }
  79. /// <summary>
  80. /// 加载PPTX文件
  81. /// </summary>
  82. /// <param name="presentationFile"></param>
  83. /// <returns></returns>
  84. public async Task<Dictionary<string, object>> ProcessPPTX(XDocument xdoc)
  85. {
  86. Dictionary<string, object> post_ary = new Dictionary<string, object>();
  87. try {
  88. var thumbnail = xdoc.GetTextByPath("//pkg:part[@pkg:name='/docProps/thumbnail.jpeg']");
  89. if (thumbnail != null) {
  90. }
  91. } catch (Exception e ) {
  92. throw new BizException(e.Message);
  93. }
  94. return null;
  95. }
  96. }
  97. }