public static WP.Paragraph GenerateParagraphWithAxialTensionFormula(Bar bar, float Ry) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); var fractionFormula = CreateFraction( new List <OpenXmlElement> { GenerateRunWithText("N") }, new List <OpenXmlElement> { GenerateRunWithText("A∙"), Index("R", "y") }); var fraction = CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{Math.Abs(bar.ActualForce)}") }, new List <OpenXmlElement> { GenerateRunWithText($"{bar.Section.Area}∙{Ry}∙"), Power("10", "2") }); officeMath.Append( fractionFormula, new Run(new Text(" = ")), fraction, new Run(new Text($" = {bar.CalcResult} " + (bar.CalcResult <= 1 ? "≤" : ">") + " 1"))); p.AppendChild(officeMath); return(p); }
public static WP.Paragraph EccentricityParagraph(Bar bar, float ecc) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); officeMath.Append( GenerateRunWithText($"e = "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"M") }, new List <OpenXmlElement> { GenerateRunWithText($"N") }), GenerateRunWithText(" = "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{bar.ActualMoment}∙ 100") }, new List <OpenXmlElement> { GenerateRunWithText($"{Math.Abs(bar.ActualForce)}") }), GenerateRunWithText($" = {ecc * 100} cм") ); p.AppendChild(officeMath); return(p); }
public static WP.Paragraph ReffEccentricityParagraph(Bar bar, float e, float m) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); officeMath.Append( GenerateRunWithText("m = e ∙ "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText("A") }, new List <OpenXmlElement> { GenerateRunWithText("W") }), GenerateRunWithText($" = {e} ∙ "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{bar.Section.Area}") }, new List <OpenXmlElement> { GenerateRunWithText($"{bar.Section.SectionModulusX}") }), GenerateRunWithText($" = {m}") ); p.AppendChild(officeMath); return(p); }
public static WP.Paragraph LambdaParagraph(Bar bar, float lambda) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); officeMath.Append( GenerateRunWithText($"λ = "), CreateFraction( new List <OpenXmlElement> { Index("l", "x"), GenerateRunWithText($"∙"), Index("μ", "x") }, new List <OpenXmlElement> { Index("i", "x") }), GenerateRunWithText(" = "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{bar.Length} ∙ 1") }, new List <OpenXmlElement> { GenerateRunWithText($"{bar.Section.RadiusOfGyrationX} ∙ 10") }), GenerateRunWithText($" = {lambda}") ); p.AppendChild(officeMath); return(p); }
public void WorkWithMathObjectType(int index, MathObjectType objectType) { Document doc = new Document(MyDir + "Shape.OfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, index, true); Assert.AreEqual(objectType, officeMath.MathObjectType); }
/// <summary> /// Called when the visiting of a OfficeMath node is ended. /// </summary> public override VisitorAction VisitOfficeMathEnd(OfficeMath officeMath) { mDocTraversalDepth--; IndentAndAppendLine("[OfficeMath end]"); mVisitorIsInsideOfficeMath = false; return(VisitorAction.Continue); }
/// <summary> /// Called when an OfficeMath node is encountered in the document. /// </summary> public override VisitorAction VisitOfficeMathStart(OfficeMath officeMath) { IndentAndAppendLine("[OfficeMath start] Math object type: " + officeMath.MathObjectType); mDocTraversalDepth++; mVisitorIsInsideOfficeMath = true; return(VisitorAction.Continue); }
public override VisitorAction VisitOfficeMathStart(OfficeMath officeMath) { if (_extractGo) { NodeCollection.Add(officeMath); } return(VisitorAction.Continue); }
public void OfficeMathDefaultValue() { Document doc = new Document(MyDir + "Shape.OfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); Assert.AreEqual(OfficeMathDisplayType.Display, officeMath.DisplayType); Assert.AreEqual(OfficeMathJustification.Center, officeMath.Justification); }
public void OfficeMathDisplayException() { Document doc = new Document(MyDir + "Shape.OfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); officeMath.DisplayType = OfficeMathDisplayType.Display; Assert.That(() => officeMath.Justification = OfficeMathJustification.Inline, Throws.TypeOf <ArgumentException>()); }
public void OfficeMathDisplayNestedObjects() { Document doc = new Document(MyDir + "Shape.NestedOfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); //Always inline Assert.AreEqual(OfficeMathDisplayType.Inline, officeMath.DisplayType); Assert.AreEqual(OfficeMathJustification.Inline, officeMath.Justification); }
public void CannotBeSetInlineDisplayWithJustification() { Document doc = new Document(MyDir + "Shape.OfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); officeMath.DisplayType = OfficeMathDisplayType.Inline; Assert.Throws <ArgumentException>(() => officeMath.Justification = OfficeMathJustification.Center); }
public static WP.Paragraph MefParagraph(float m, float etta, float mef) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); officeMath.Append( Index("m", "ef"), GenerateRunWithText($" = m ∙ η = {m} ∙ {etta} = {mef}")); p.AppendChild(officeMath); return(p); }
public void SaveShapeObjectAsImage() { //ExStart //ExFor:Shows how to convert specific object into image Document doc = new Document(MyDir + "Document.OfficeMath.docx"); //Get OfficeMath node from the document and render this as image (you can also do the same with the Shape node) OfficeMath math = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); math.GetMathRenderer().Save(MyDir + "Document.OfficeMath Out.svg", new ImageSaveOptions(SaveFormat.Svg)); //ExEnd }
public void MathEquations() { //ExStart:MathEquations Document doc = new Document(MyDir + "Office math.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); // OfficeMath display type represents whether an equation is displayed inline with the text or displayed on its line. officeMath.DisplayType = OfficeMathDisplayType.Display; officeMath.Justification = OfficeMathJustification.Left; doc.Save(ArtifactsDir + "WorkingWithOfficeMath.MathEquations.docx"); //ExEnd:MathEquations }
private void button1_Click(object sender, EventArgs e) { string[] latexMathCode = { @"x^{2}+\\sqrt{x^{2}+1}=2", @"2\alpha - \sin y + x", @"1 \over 2 + x", @"(1 + \vert x-[a-b] \vert)", @"\mbox{if $x=1$ or $x=2$}", @"\begin{cases} 1 & \mbox{if $x>0$,} \\ 2 & \mbox{otherwise.} \end{cases}" }; Document doc = new Document(); doc.LoadFromFile(@"..\..\..\..\..\..\Data\AddMathEquation.docx"); Section section = doc.Sections[0]; Paragraph paragraph; OfficeMath officeMath; //Add LaTeX code Table table1 = section.Tables[0] as Table; List <OfficeMath> mathEquations = new List <OfficeMath>(); for (int i = 1; i < 7; i++) { paragraph = table1.Rows[i].Cells[0].AddParagraph(); paragraph.Text = latexMathCode[i - 1]; paragraph = table1.Rows[i].Cells[1].AddParagraph(); officeMath = new OfficeMath(doc); officeMath.FromLatexMathCode(latexMathCode[i - 1]); paragraph.Items.Add(officeMath); mathEquations.Add(officeMath); } //Add MathML code Table table2 = section.Tables[1] as Table; for (int i = 1; i < 7; i++) { paragraph = table2.Rows[i].Cells[0].AddParagraph(); paragraph.Text = mathEquations[i - 1].ToMathMLCode(); paragraph = table2.Rows[i].Cells[1].AddParagraph(); officeMath = new OfficeMath(doc); officeMath.FromMathMLCode(mathEquations[i - 1].ToMathMLCode()); paragraph.Items.Add(officeMath); } string result = "AddMathEquation_result.docx"; doc.SaveToFile(result, FileFormat.Docx); WordDocViewer(result); }
public void OfficeMathDisplayGold() { //ExStart //ExFor:OfficeMath.DisplayType //ExFor:OfficeMath.Justification //ExSummary:Shows how to set office math display formatting. Document doc = new Document(MyDir + "Shape.OfficeMath.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); officeMath.DisplayType = OfficeMathDisplayType.Display; officeMath.Justification = OfficeMathJustification.Left; doc.Save(MyDir + @"Artifacts\Shape.OfficeMath.docx"); //ExEnd Assert.IsTrue(DocumentHelper.CompareDocs(MyDir + @"Artifacts\Shape.OfficeMath.docx", MyDir + @"\Golds\Shape.OfficeMath Gold.docx")); }
public static void Run() { // ExStart:SpecifylocaleAtFieldlevel // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithFields(); Document doc = new Document(dataDir + "MathEquations.docx"); OfficeMath officeMath = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true); // Gets/sets Office Math display format type which represents whether an equation is displayed inline with the text or displayed on its own line. officeMath.DisplayType = OfficeMathDisplayType.Display; // or OfficeMathDisplayType.Inline // Gets/sets Office Math justification. officeMath.Justification = OfficeMathJustification.Left; // Left justification of Math Paragraph. doc.Save(dataDir + "MathEquations_out.docx"); // ExEnd:SpecifylocaleAtFieldlevel }
public static WP.Paragraph LambdaRefParagraph(float lambda, float lambdaRef, float Ry, float E) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); var bar = new DocumentFormat.OpenXml.Math.Bar(); var barProperties = new BarProperties(); var position = new Position() { Val = VerticalJustificationValues.Top }; barProperties.Append(position); var bas = new Base(new Run(new Text("λ"))); bar.Append(barProperties, bas); officeMath.Append( bar, GenerateRunWithText(" = λ ∙ "), CreateRadical( CreateFraction( new List <OpenXmlElement> { Index("R", "y") }, new List <OpenXmlElement> { GenerateRunWithText("E") })), GenerateRunWithText($" = {lambda} "), CreateRadical( CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{Ry}") }, new List <OpenXmlElement> { GenerateRunWithText($"{E}") })), GenerateRunWithText(" = "), GenerateRunWithText($" = {lambdaRef}") ); p.AppendChild(officeMath); return(p); }
public static WP.Paragraph AreaFractionParagraph(Bar bar, float afaw) { var p = new WP.Paragraph(); var officeMath = new OfficeMath(); officeMath.Append( CreateFraction( new List <OpenXmlElement> { Index("A", "f") }, new List <OpenXmlElement> { Index("A", "w") }), GenerateRunWithText(" = "), CreateFraction( new List <OpenXmlElement> { Index("b", "f"), GenerateRunWithText(" ∙ "), Index("t", "f") }, new List <OpenXmlElement> { GenerateRunWithText("2 ∙ "), Index("h", "w"), GenerateRunWithText(" ∙ "), Index("t", "w") }), GenerateRunWithText(" = "), CreateFraction( new List <OpenXmlElement> { GenerateRunWithText($"{bar.Section.Width} ∙{bar.Section.Thickness}") }, new List <OpenXmlElement> { GenerateRunWithText($"2 ∙ {bar.Section.Height} ∙ {bar.Section.Thickness}") }), GenerateRunWithText($" = {afaw}") ); p.AppendChild(officeMath); return(p); }
public static void getFormulaXml(WordprocessingDocument doc, String xmlFullPath) { Body body = doc.MainDocumentPart.Document.Body; IEnumerable <Paragraph> paras = body.Elements <Paragraph>(); XmlDocument xmlDocx = new XmlDocument(); xmlDocx.Load(xmlFullPath); XmlNode root = xmlDocx.SelectSingleNode("Formula/spErroInfo"); List <Paragraph> pList = toList(paras); int count = -1; List <int> iList = Tool.getTitlePosition(doc); string chapter = ""; string last_chapter = null; foreach (Paragraph p in paras) { Run r = p.GetFirstChild <Run>(); if (r != null) { EmbeddedObject Ob = null; OfficeMath oMath = null; count++; Ob = r.GetFirstChild <EmbeddedObject>(); oMath = r.GetFirstChild <OfficeMath>(); if (Ob != null || oMath != null) { if (pList != null && count < pList.Count - 1) { ParagraphProperties pPr = p.GetFirstChild <ParagraphProperties>(); List <int> listchapter = Tool.getTitlePosition(doc); chapter = Chapter(listchapter, count, body); int num_incap = 1; if (chapter == last_chapter) { num_incap++; } else if (chapter != last_chapter) { num_incap = 1; last_chapter = chapter; } //公式编号 string number = getFullText(p); string Show_number = number.Trim(); bool Isformule = false; int FirstNumber = 0; bool sameP = false; bool havePicturename = false; for (int a = 0; a < number.Length; a++) { if (number[a] == '图') { sameP = true; } } for (int i = 0; i < number.Length; i++) { if (number[i] >= 48 && number[i] <= 58 && FirstNumber == 0 && sameP == false) { Isformule = true; if (i != 0) { FirstNumber = i; } } else if (number[i] >= 48 && number[i] <= 58 && FirstNumber != 0 && sameP == false) { /*if (number[i - 1] != '(') * { * XmlElement xml = xmlDocx.CreateElement("Text"); * xml.InnerText = "公式编号格式不规范,建议改为(M.N):{" + Show_number + "}"; * root.AppendChild(xml); * }*/ } else { Paragraph Nextline = pList[count + 1]; string NL = getFullText(Nextline); for (int j = 0; j < NL.Length; j++) { if ((NL[j] == '图' && j == 0) || (NL[j] == 'F' && j == 0)) { havePicturename = true; /*Isformule = true; * XmlElement xml = xmlDocx.CreateElement("Text"); * xml.InnerText = "公式缺少编号:{" + chapter + "}"; * root.AppendChild(xml);*/ } if ((NL[j] == '图' && j != 0) || (NL[j] == 'F' && j != 0)) { havePicturename = true; /*if (NL[j - 1] != ' ') * { * Isformule = true; * XmlElement xml = xmlDocx.CreateElement("Text"); * xml.InnerText = "公式缺少编号:{" + chapter + "}"; * root.AppendChild(xml); * }*/ } } if (havePicturename == false) { Isformule = true; XmlElement xml = xmlDocx.CreateElement("Text"); xml.InnerText = "公式缺少编号:{" + chapter + "}"; root.AppendChild(xml); } } } //右对齐 if (pPr != null && Isformule == true) { if (pPr.GetFirstChild <Justification>() != null) { if (pPr.GetFirstChild <Justification>().Val != null) { if (pPr.GetFirstChild <Justification>().Val != "right") { if (Show_number != null) { XmlElement xml = xmlDocx.CreateElement("Text"); xml.InnerText = "公式应整行右对齐:{" + Show_number + "}"; root.AppendChild(xml); } if (Show_number == null) { } } } } } //公式前后行距 if (pPr != null && Isformule == true) { if (pPr.GetFirstChild <SpacingBetweenLines>() != null) { if (pPr.GetFirstChild <SpacingBetweenLines>().Before != null && pPr.GetFirstChild <SpacingBetweenLines>().Before != "156") { if (Show_number != null) { XmlElement xml = xmlDocx.CreateElement("Text"); xml.InnerText = "公式段前间距错误,应为0.5倍行距:{" + "}"; root.AppendChild(xml); } if (Show_number == null) { } } if (pPr.GetFirstChild <SpacingBetweenLines>().After != null && pPr.GetFirstChild <SpacingBetweenLines>().After != "156") { if (Show_number != null) { XmlElement xml = xmlDocx.CreateElement("Text"); xml.InnerText = "公式段前间距错误,应为0.5倍行距:{" + "}"; root.AppendChild(xml); } if (Show_number == null) { } } } } } } } } xmlDocx.Save(xmlFullPath); }
//首先找到公式 public void SelectandCheckFormula(WordprocessingDocument doc) { Body body = doc.MainDocumentPart.Document.Body; IEnumerable <Paragraph> paras = body.Elements <Paragraph>(); List <Paragraph> plist = Tool.toList(paras); var list = body.ChildElements; List <int> titleposition = Tool.getTitlePosition(doc); Paragraph temp = new Paragraph(); int count = 0; int number = -1; foreach (var t in list) { count++; if (t.GetType() == temp.GetType()) { Paragraph p = (Paragraph)t; Run r = t.GetFirstChild <Run>(); number++; if (r != null) { EmbeddedObject ob = r.GetFirstChild <EmbeddedObject>(); OfficeMath om = r.GetFirstChild <OfficeMath>(); Picture pic = null; IEnumerable <Run> runs = p.Elements <Run>(); foreach (Run rr in runs) { if (rr.GetFirstChild <Picture>() != null) { pic = rr.GetFirstChild <Picture>(); } } if (ob != null || om != null || pic != null) { if (plist != null && number < plist.Count - 1) { /* * string chaper = Chapter(titleposition, count, body); * if (CharpterNum != chaper.Trim().Substring(0, 1)) * { * //正确的章节号 * CharpterNum = chaper.Trim().Substring(0, 1); * //每章节的公式序号 * CharpterFormulaN = 0; * }*/ string content = Util.getFullText(p); string showcontent = content.Trim(); int firstnum = 0; bool formula = false; bool rightformula = false; bool special = false; bool samep = false; bool haspicname = false; bool ispicture = false; int i; //是图 for (i = 0; i < content.Length; i++) { if (content[i] == '图') { samep = true; } } //一般来说 公式的图片和后面的序号在同一paragraph里 可据此判断是否为公式 for (i = 0; i < content.Length; i++) { if (content[i] > 48 && content[i] < 58 && firstnum == 0 && samep == false) { // rightformula = true; formula = true; break; } } if (!rightformula) { Paragraph nextl = plist[number + 1]; string nl = Util.getFullText(nextl); //图片的下一paragraph里有“图”字 可判断此图片是图 for (i = 0; i < nl.Length; i++) { if (nl[i] == '图' || nl[i] == 'F') { haspicname = true; } } if (number < plist.Count - 3) { if (plist[number + 2].InnerText.IndexOf('.') >= 0 && plist[number + 2].InnerText.IndexOf('图') >= 0) { haspicname = true; } //图片的上一行有“如图x.x”字样 则图片是图 if (plist[number - 1].InnerText.IndexOf("如图") >= 0 || /*(plist[number - 1].InnerText == null &&*/ plist[number - 2].InnerText.IndexOf("如图") >= 0) { ispicture = true; } } } if (Regex.IsMatch(p.InnerText, @"[\u4e00-\u9fa5]")) { special = true; } if (!samep && !haspicname && !ispicture && !special) { // Console.WriteLine(plist[number+1].InnerText); // Console.WriteLine(plist[number - 2].InnerText); // Console.WriteLine(p.InnerText); WhetherJustif(p);//公式部分是否居中 HasNumber(p, doc, count, titleposition); //是否有编号 Checkbracket(p); //括号是否正确 if (!Util.correctJustification(p, doc, Justifi)) { Util.printError("公式整行未右对齐 ----" + "第" + Chapternum + "章" + "第" + Sequencenum + "个公式");//是否右对齐 } //if (!Util.correctSpacingBetweenLines_Be(p, doc, textBef)) // Util.printError("公式的段前间距错误,应为段前0.5行 ----" + "第" + Chapternum + "章" + "第" + Sequencenum + "个公式"); //if (!Util.correctSpacingBetweenLines_Af(p, doc, textAft)) // Util.printError("公式的段后间距错误,应为段后0.5行 ----" + "第" + Chapternum + "章" + "第" + Sequencenum + "个公式"); } else { continue; } } } } } } }
public string xuatpdf(long id, string tenmon) { Document doc = new Document(); Section section = doc.AddSection(); section.PageSetup.Borders.BorderType = BorderStyle.DoubleWave; section.PageSetup.Borders.Color = Color.Black; section.PageSetup.Borders.Left.Space = 50; section.PageSetup.Borders.Right.Space = 50; section.PageSetup.Borders.Top.Space = 20; section.PageSetup.Borders.Bottom.Space = 20; //title Paragraph paratitle = section.AddParagraph(); paratitle.Format.HorizontalAlignment = HorizontalAlignment.Center; paratitle.AppendText("TRƯỜNG ĐẠI HỌC GIAO THÔNG VẬN TẢI PHÂN HIỆU TẠI TP HỒ CHÍ MINH"); ParagraphStyle styletitle = new ParagraphStyle(doc); styletitle.Name = "titleStyle"; styletitle.CharacterFormat.Bold = true; styletitle.CharacterFormat.TextColor = Color.Black; styletitle.CharacterFormat.FontName = "Arial"; styletitle.CharacterFormat.FontSize = 16f; doc.Styles.Add(styletitle); paratitle.ApplyStyle("titleStyle"); // tne mon de thi Paragraph paratenmon = section.AddParagraph(); paratenmon.Format.HorizontalAlignment = HorizontalAlignment.Left; paratenmon.AppendText("\n\nĐề thi môn:" + tenmon); ParagraphStyle styleleft = new ParagraphStyle(doc); styleleft.Name = "left"; styleleft.CharacterFormat.Bold = true; styleleft.CharacterFormat.TextColor = Color.Black; styleleft.CharacterFormat.FontName = "Arial"; styleleft.CharacterFormat.FontSize = 12f; doc.Styles.Add(styleleft); paratenmon.ApplyStyle("left"); // ma de thi Paragraph paramade = section.AddParagraph(); paramade.Format.HorizontalAlignment = HorizontalAlignment.Right; paramade.AppendText("\tMã đề:" + id + "\n\n\n"); ParagraphStyle styleright = new ParagraphStyle(doc); styleright.Name = "right"; styleright.CharacterFormat.Bold = true; styleright.CharacterFormat.TextColor = Color.Black; styleright.CharacterFormat.FontName = "Arial"; styleright.CharacterFormat.FontSize = 12f; doc.Styles.Add(styleright); paramade.ApplyStyle("right"); int slcau = 0; var khoch = new Bode().listkhocauhoi(id); foreach (var item in khoch) { Paragraph para1 = section.AddParagraph(); slcau++; int slda = 0; var s = tachcongthuc(item.NoiDung); para1.AppendText("\n"); para1.AppendText("Câu " + slcau + ":"); foreach (var item2 in s) { if (item2.Contains("<mml:math")) { try { OfficeMath officeMath; officeMath = new OfficeMath(doc); officeMath.FromMathMLCode(item2); para1.Items.Add(officeMath); } catch { } } else { para1.AppendHTML(item2); } } para1.AppendText("\n\n"); if (item.HinhAnh.Length > 0) { try { Image image = Image.FromFile(Server.MapPath(item.HinhAnh)); DocPicture pic = para1.AppendPicture(image); pic.Height = pic.Height; if (pic.Height > pic.Width) { pic.Height = 180; pic.Width = 120; } else if (pic.Height < pic.Width) { pic.Height = 120; pic.Width = 150; } else if (pic.Height == pic.Width) { pic.Height = 150; pic.Width = 150; } para1.AppendText("\n"); } catch { } } foreach (var da in item.Dap_AN) { var s1 = tachcongthuc(da.NoiDung); para1.AppendText("\n"); if (da.TrangThai == true) { para1.AppendText("*"); } else { para1.AppendText(""); } slda++; foreach (var item2 in s1) { if (item2.Contains("<mml:math")) { try { OfficeMath officeMath; officeMath = new OfficeMath(doc); officeMath.FromMathMLCode(item2); para1.Items.Add(officeMath); } catch { } } else { para1.AppendHTML(item2); } } if (da.HinhAnh.Length > 0) { try { para1.AppendText("\n\n"); Image image = Image.FromFile(Server.MapPath(da.HinhAnh)); DocPicture pic = para1.AppendPicture(image); if (pic.Height > pic.Width) { pic.Height = 120; pic.Width = 100; } else if (pic.Height < pic.Width) { pic.Height = 100; pic.Width = 120; } else if (pic.Height == pic.Width) { pic.Height = 120; pic.Width = 120; } para1.AppendText("\n"); } catch { } } } } Paragraph paragraph = section.Paragraphs[section.Count - 1]; Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote); TextRange text = footnote.TextBody.AddParagraph().AppendText("HẾT"); text.CharacterFormat.FontName = "Arial Black"; text.CharacterFormat.FontSize = 12; text.CharacterFormat.TextColor = Color.SlateGray; doc.SaveToFile(Server.MapPath("~/Content/" + "De_" + id + ".docx")); doc.SaveToFile(Server.MapPath("~/Content/" + "De_" + id + ".pdf")); return("/Content/" + "De_" + id + ".pdf"); }