我正在使用 Docx dll 生成 pdf 文件,但无法在标题中添加图像,尽管我可以在 word 文件的内容部分添加图像。这是我的代码:
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();
}
任何帮助都会很棒!