LEIYI 6 months ago
parent
commit
601da6226e

+ 47 - 49
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -27,6 +27,7 @@ using System.Collections;
 using System.Data;
 using System.Diagnostics;
 using System.Globalization;
+using System.IO;
 using System.Reflection.PortableExecutable;
 using Ubiety.Dns.Core;
 using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
@@ -10798,45 +10799,7 @@ ORDER by  gctggrc.id DESC
             DocumentBuilder builder = new DocumentBuilder(doc);
             try
             {
-                #region 设置页眉
-
-                string voucherHeaderPath = $"./Images/VoucherHeader.png";
-
-
-                builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
-
-                //靠右
-                builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
-                //   设置页脚上下边距
-                builder.PageSetup.HeaderDistance = 42;
-
-                //   添加页眉线
-                Aspose.Words.Border borderHeader = null;
-                try
-                {
-                    borderHeader = builder.ParagraphFormat.Borders.Bottom;
-                }
-                catch (Exception e)
-                {
-                    // TODO Auto-generated catch block
-                    //e.printStackTrace();
-                }
-                borderHeader.Shadow = true;
-                borderHeader.DistanceFromText = 2;
-                borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
-
-
-
-                if (System.IO.File.Exists(voucherHeaderPath))
-                {
-                    //页眉加载图片
-                    var image = Image.FromFile(voucherHeaderPath);
-
-                    builder.InsertImage(image, RelativeHorizontalPosition.Default, 1, RelativeVerticalPosition.Margin, 1, 1.20, 2.70, WrapType.Inline);
-                }
-               
-
-                #endregion
+                
 
 
                 builder.MoveToDocumentStart();
@@ -11222,17 +11185,52 @@ ORDER by  gctggrc.id DESC
                     builder.Writeln("");
                 }
 
-                //// 遍历文档中的所有段落
-                //foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
-                //{
-                //    // 设置段落的字体样式
-                //    // 这里我们设置字体为Times New Roman,大小为12,加粗
-                //    para.ParagraphFormat.Style.Font.Name = "微软雅黑";
-                //    para.ParagraphFormat.Style.Font.Size = 12;
-                //    para.ParagraphFormat.Style.Font.Bold = true;
-                //}
 
-                
+
+                #region 设置页眉
+
+                builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
+                string voucherHeaderPath = $"./Images/VoucherHeader.png";
+                if (System.IO.File.Exists(voucherHeaderPath))
+                {
+                    byte[] imageBytes = System.IO.File.ReadAllBytes(voucherHeaderPath);
+                    //Image image = Image.FromStream(imageBytes, ImageType.Png);
+                    //builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 0, RelativeVerticalPosition.Margin, 0, 81, 36, WrapType.None);
+                    Shape shape = builder.InsertImage(imageBytes);
+
+                    // 调整图片位置
+                    shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; // 将图片的水平位置设置为页面
+                    shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin; // 将图片的垂直位置设置为页眉上边距
+                    shape.Top = 50; // 将图片距离页眉上边缘的距离
+                    shape.Left = 0; // 将图片距离页面左边缘的距离
+                    shape.Width = 81; // 设置图片宽度
+                    shape.Height = 36; // 设置图片高度
+                }
+
+                //靠右
+                builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
+                ////   设置页脚上下边距
+                //builder.PageSetup.HeaderDistance = 42;
+
+                //   添加页眉线
+                Aspose.Words.Border borderHeader = null;
+                try
+                {
+                    borderHeader = builder.ParagraphFormat.Borders.Bottom;
+                }
+                catch (Exception e)
+                {
+                    // TODO Auto-generated catch block
+                    //e.printStackTrace();
+                }
+                borderHeader.Shadow = true;
+                borderHeader.DistanceFromText = 2;
+                borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
+
+
+
+                #endregion
+
 
             }
             catch (Exception ex)

BIN
OASystem/OASystem.Api/Images/VoucherHeader.jpg