asp.net – 如何使用Docx dll生成word文档时在标题中添加图像和
发布时间:2020-12-16 06:23:04 所属栏目:asp.Net 来源:网络整理
导读:虽然我可以在word文件的内容部分添加图像,但我正在使用Docx dll生成pdf文件,但无法在标题中添加图像.这是我的代码: using (Novacode.DocX document = Novacode.DocX.Create(savePath)) { // Add Header and Footer support to this document. document.AddH
虽然我可以在word文件的内容部分添加图像,但我正在使用Docx dll生成pdf文件,但无法在标题中添加图像.这是我的代码:
using (Novacode.DocX document = Novacode.DocX.Create(savePath)) { // Add Header and Footer support to this document. document.AddHeaders(); document.AddFooters(); // Get the default Header for this document. Novacode.Header header_default = document.Headers.odd; // Add an Image to the docx file string imageName = "LOGO.png"; string url = Request.MapPath("/PDFFolder/" + imageName); Novacode.Image img = document.AddImage(url); // Insert a Paragraph into the default Header. Novacode.Picture pic1 = img.CreatePicture(); Novacode.Paragraph p1 = header_default.InsertParagraph(); header_default.Pictures.Add(pic1); p1.Append("Some more text").Bold(); // Add a new Paragraph to the document. Novacode.Paragraph p = document.InsertParagraph(); // Append some text. p.Append(textword).Font(new myDrawing.FontFamily("Arial")); // Get the default Footer for this document. Novacode.Footer footer_default = document.Footers.odd; // Insert a Paragraph into the default Footer. Novacode.Paragraph p3 = footer_default.InsertParagraph(); p3.Append("Hello Footer.").Bold(); // Save the document. document.Save(); } 任何帮助都会很棒!! 解决方法
我得到了问题的答案.实际上似乎Docx DLL不支持在标题下的表格中显示图像.虽然他们已经给出了在桌面上显示图像并在博客中显示的方法,但我仍然无法使用标题部分中的表格来显示图像,我可以通过使用如下面的代码中的段落轻松完成:
// Insert pic and text into the default Header. Novacode.Paragraph p1 = header_default.InsertParagraph(); p1.Direction = Novacode.Direction.LeftToRight; p1.AppendPicture(pic1); 它工作正常但是当你必须显示带有一些标题文本的图像时会出现问题.因为我们没有使用表来显示图像所以很难正确对齐图像和标题文本.在尝试了这么多解决方案和努力工作之后,我没有找到任何支持和解决方案,最后我找到了解决问题的方法.我们可以将标题图像和标题文本对齐在一行中,而不使用下面给出一行的表格: p1.Append("Headertext").Bold().Position(30); 在Position()方法的帮助下,您可以将标题文本和标题图像对齐在一行中.希望这也有助于某人:). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – Jquery AJAX成功没有被Coded UI测试项目触发
- asp.net-mvc – Razor不会在HiddenFor中呈现隐藏的准确PK
- asp.net-mvc – 死简单的ASP.NET MVC 5密码保护?
- asp.net-core – 具有取消令牌的自定义AspCore中间件
- asp.net – 从请求中获取所有发布数据
- asp.net – Web API外部承载未经授权
- asp.net – 将页脚粘贴到页面底部的方法
- asp.net-mvc – MVC 5 OWIN登录声明和AntiforgeryToken.我错
- 加载ASP.Net MVC JSONResult jQuery DataTables
- asp.net – 以编程方式将Textbox TemplateField列添加到Gri
推荐文章
站长推荐
热点阅读