Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Mon Sep 30, 2024 8:06 pm
I have a .docx document, where footer contains an image (but not on the first page).
(I attached .zip archive with this file)
The problem is I don't know how to access this image, here is my code:
- Code: Select all
foreach (HeaderFooter headerFooter in document.Sections[0].HeadersFooters)
{
foreach (Paragraph paragraph in headerFooter.Paragraphs)
{
foreach (DocumentObject docObj in paragraph.ChildObjects)
{
if (docObj.DocumentObjectType == DocumentObjectType.Picture)
{
// some changes in picture, but it doesn't get here!
}
}
}
}
Login to view the files attached to this post.
-

volodymyr04
-
- Posts: 2
- Joined: Mon Sep 30, 2024 7:54 pm
Tue Oct 01, 2024 7:06 am
Hello,
Thanks for your inquiry.
Kindly note that the image you want to extract is in the table in the footer, and the code for obtaining the image is as follows. If you have any other questions, please feel free to write to me at any time.
- Code: Select all
Document document = new Document();
document.LoadFromFile("D:\\music\\example\\example.docx");
HeaderFooter footer = document.Sections[0].HeadersFooters.Footer;
int index = 0;
for (int i = 0; i < footer.ChildObjects.Count; i++)
{
DocumentObject documentObject = footer.ChildObjects[i];
if (documentObject is Table)
{
Table table = (Table)documentObject;
for (int j = 0; j < table.Rows.Count; j++)
{
for (int k = 0; k < table.Rows[j].Cells.Count; k++)
{
TableCell tableCell = table.Rows[j].Cells[k];
for (int i1 = 0; i1 < tableCell.ChildObjects.Count; i1++)
{
if(tableCell.ChildObjects[i1] is Paragraph){
Paragraph para = (Paragraph)tableCell.ChildObjects[i1];
foreach (DocumentObject docObj in para.ChildObjects)
{
if (docObj.DocumentObjectType == DocumentObjectType.Picture)
{
DocPicture picture = docObj as DocPicture;
picture.Image.Save(string.Format("img_{0}.png", index), System.Drawing.Imaging.ImageFormat.Png);
}
}
}
}
}
}
}
}
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 472
- Joined: Mon Dec 27, 2021 2:23 am
Tue Oct 01, 2024 8:20 am
It helped, thank you!
-

volodymyr04
-
- Posts: 2
- Joined: Mon Sep 30, 2024 7:54 pm
Wed Oct 02, 2024 9:37 am
Hello,
Thanks for your feedback. Glad to hear that news, if you have any other questions in the future, please feel free to write to us at any time.
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 472
- Joined: Mon Dec 27, 2021 2:23 am