使用Spire.doc库将docX转换为PDF时,标题中的图像丢失

使用Spire.doc库将docX转换为PDF时,标题中的图像丢失,pdf,novacode-docx,spire.doc,Pdf,Novacode Docx,Spire.doc,我使用docX库创建了一个docX,并在标题中添加了一个图像。但是,当我使用Spire.doc库将docX转换为PDF时,图像丢失。知道为什么吗?下面是我的代码: var doc = DocX.Create(fileName); string url = @"C:\Users\Desktop\Capture.JPG"; Novacode.Image img = doc.AddImage(url); Picture pic = img.CreatePicture(); doc.AddHeaders

我使用docX库创建了一个docX,并在标题中添加了一个图像。但是,当我使用Spire.doc库将docX转换为PDF时,图像丢失。知道为什么吗?下面是我的代码:

var doc = DocX.Create(fileName);
string url = @"C:\Users\Desktop\Capture.JPG";
Novacode.Image img = doc.AddImage(url);
Picture pic = img.CreatePicture();
doc.AddHeaders();
Header header_default = doc.Headers.odd;
Paragraph p1 = header_default.InsertParagraph();
p1.Append(headerText).Bold().Color(System.Drawing.Color.LightGray).FontSize(20);
p1.AppendPicture(pic);

doc.Save();
Document docS = new Document();
docS.LoadFromFile(fileName);
string pdfPath = @"C:\Users\Documents\toPDF.PDF";
docS.SaveToFile(pdfPath, FileFormat.PDF);

既然您已经在代码中使用了Spire.Doc,为什么不直接使用Spire在Word中创建头文件,然后将文件保存为PDF文件格式呢。我尝试了以下代码,效果很好

using Spire.Doc;
using System.Drawing;
using Spire.Doc.Documents;

namespace Doc2Pdf
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            Section section = doc.AddSection();

            HeaderFooter header = section.HeadersFooters.Header;
            Paragraph p1 = header.AddParagraph();
            Image image = Image.FromFile("pic.png");
            p1.AppendPicture(image);

            doc.SaveToFile("Header.pdf", FileFormat.PDF);
        }
    }
}

既然您已经在代码中使用了Spire.Doc,为什么不直接使用Spire在Word中创建头文件,然后将文件保存为PDF文件格式呢。我尝试了以下代码,效果很好

using Spire.Doc;
using System.Drawing;
using Spire.Doc.Documents;

namespace Doc2Pdf
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            Section section = doc.AddSection();

            HeaderFooter header = section.HeadersFooters.Header;
            Paragraph p1 = header.AddParagraph();
            Image image = Image.FromFile("pic.png");
            p1.AppendPicture(image);

            doc.SaveToFile("Header.pdf", FileFormat.PDF);
        }
    }
}