I try convert html to PDF by following code but output PDF is not correct layout as HTML page:
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 12, Left = 12, Right = 12, Bottom = 12 },
DocumentTitle = "",
Out = filenames
},
Objects = { new ObjectSettings
{
PagesCount = true,
HtmlContent = html,
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { FontName = "Arial", FontSize = 8, Left = $"PTT Group Ship Vetting - {id}", Right = "Page [page] of [toPage]", Line = false },
} }
};
var converter = new SynchronizedConverter(new PdfTools());
byte[] pdfByte = converter.Convert(pdf);
this is HTML input
This is PDF output
Related
I tried to create a word document with page number in Header. I used SimpleField to insert Page number and page count.
But, these fields are not impacted by Color and font size defined in the RunProperties, unlike the text (as it's showed in the picture below).
How to format SimpleField??
Thanks
private static void CreateReport(string filename)
{
using (var mem = new MemoryStream())
{
using (var wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true))
{
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure
mainPart.Document = new Document();
mainPart.Document.Body = new Body();
//Create paragraph for header
var paragraph = new Paragraph();
var run = paragraph.AppendChild(new Run());
run.Append(new RunProperties()
{
Bold = new Bold(),
FontSize = new FontSize() { Val = "48" },
Color = new Color() { Val = "FF0000" /*red*/ }
}
);
run.Append(new Text() { Text = "Page:" });
run.Append(new SimpleField() { Instruction = #"PAGE" });
run.Append(new Text() { Text = "/" });
run.Append(new SimpleField() { Instruction = #"SECTIONPAGES" });
//Add paragraph to header
AddParagraphToHeader(mainPart, paragraph);
//Save document
wordDocument.SaveAs(filename);
}
}
}
private static void AddParagraphToHeader(MainDocumentPart mainPart, Paragraph paragraph)
{
var part = mainPart.AddNewPart<HeaderPart>();
var header = new Header() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } };
header.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
header.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
header.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
header.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
header.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
header.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
header.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
header.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
header.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
header.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
header.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
header.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
header.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
header.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
header.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
paragraph.RsidParagraphAddition = "00164C17";
paragraph.RsidRunAdditionDefault = "00164C17";
header.Append(paragraph);
part.Header = header;
var headerPartId = mainPart.GetIdOfPart(part);
mainPart.Document.PrependChild<HeaderReference>((new HeaderReference() { Id = headerPartId }));
}
After fighting with this, I found a solution that works for me -- SimpleField is the wrong thing to use for this scenario, you need to end up with a w:instrText by generating FieldChar and FieldCode objects, which means your code needs to be something like this:
Run PageNumRun = new Run(
new Text() { Text = "PAGE ", Space = SpaceProcessingModeValues.Preserve },
new FieldChar { FieldCharType = FieldCharValues.Begin },
new FieldCode("PAGE"), // This is the "Instruction" from the SimpleField
new FieldChar { FieldCharType = FieldCharValues.End },
new Text() { Text = " OF ", Space = SpaceProcessingModeValues.Preserve },
new FieldChar { FieldCharType = FieldCharValues.Begin },
new FieldCode("NUMPAGES"), // This is the "Instruction" from the SimpleField
new FieldChar { FieldCharType = FieldCharValues.End }
);
This will honor your Run font characteristics for the automatically generated values.
I need to create a Word Document using Open XML SDK. I have the document text and the Footnotes . I am using the below Snippets to Create the Word Document.
I am able to create the document with the text ,But I am not able to add Footnotes to it.
Can you please let us know how to add FootNotes programmatically using Open Xml
public void CreateWordDocument()
{
using (MemoryStream DocxMemory = new MemoryStream())
{
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(DocxMemory, WordprocessingDocumentType.Document, true))
{
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure and add some text.
this.AddSettingsToMainDocumentPart(mainPart);
StyleDefinitionsPart part = mainPart.StyleDefinitionsPart;
// If the Styles part does not exist, add it.
if (part == null)
{
this.AddStylesPartToPackage(mainPart);
}
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
Paragraph Para = body.AppendChild(new Paragraph());
Run run = Para.AppendChild(new Run());
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("This is main text of the document"));
var footnotesPart = mainPart.AddNewPart<FootnotesPart>("rId1");
this.GenerateFooterPartContent(mainPart.FootnotesPart);
mainPart.Document.Save();
wordDocument.Close();
MemoryStream Result = new MemoryStream();
DocxMemory.Seek(0, SeekOrigin.Begin);
DocxMemory.CopyTo(Result);
Result.Position = 0;
////Citation processing
byte[] BufferFileData = new byte[Result.Length];
Result.Read(BufferFileData, 0, (int)Result.Length);
File.WriteAllBytes("Output1.docx", BufferFileData);
}
}
}
private void AddSettingsToMainDocumentPart(MainDocumentPart part)
{
DocumentSettingsPart settingsPart = part.DocumentSettingsPart;
if (settingsPart == null)
settingsPart = part.AddNewPart<DocumentSettingsPart>();
settingsPart.Settings = new Settings(
new Compatibility(
new CompatibilitySetting()
{
Name = new EnumValue<CompatSettingNameValues>
(CompatSettingNameValues.CompatibilityMode),
Val = new StringValue("14"),
Uri = new StringValue
("http://schemas.microsoft.com/office/word")
}
)
);
settingsPart.Settings.Save();
}
private StyleDefinitionsPart AddStylesPartToPackage(MainDocumentPart mainPart)
{
StyleDefinitionsPart part;
part = mainPart.AddNewPart<StyleDefinitionsPart>();
Styles root = new Styles();
root.Save(part);
return part;
}
// Generates content of part.
private void GenerateFooterPartContent(FootnotesPart part)
{
Footnotes footnotes1 = new Footnotes() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } };
footnotes1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
footnotes1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
footnotes1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
footnotes1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
footnotes1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
footnotes1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
footnotes1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
footnotes1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
footnotes1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
footnotes1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
footnotes1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
footnotes1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
footnotes1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
footnotes1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
footnotes1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
Footnote footnote1 = new Footnote() { Type = FootnoteEndnoteValues.Separator, Id = -1 };
Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "003F1A60", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "003F1A60" };
Run run1 = new Run();
SeparatorMark separatorMark1 = new SeparatorMark();
run1.Append(separatorMark1);
paragraph1.Append(run1);
footnote1.Append(paragraph1);
Footnote footnote2 = new Footnote() { Type = FootnoteEndnoteValues.ContinuationSeparator, Id = 0 };
Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "003F1A60", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "003F1A60" };
Run run2 = new Run();
ContinuationSeparatorMark continuationSeparatorMark1 = new ContinuationSeparatorMark();
run2.Append(continuationSeparatorMark1);
paragraph2.Append(run2);
footnote2.Append(paragraph2);
Footnote footnote3 = new Footnote() { Id = 1 };
Paragraph paragraph3 = new Paragraph() { RsidParagraphMarkRevision = "009774CC", RsidParagraphAddition = "00626544", RsidParagraphProperties = "00626544", RsidRunAdditionDefault = "00626544" };
ParagraphProperties paragraphProperties1 = new ParagraphProperties();
ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
RunFonts runFonts1 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
FontSize fontSize1 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript() { Val = "24" };
paragraphMarkRunProperties1.Append(runFonts1);
paragraphMarkRunProperties1.Append(fontSize1);
paragraphMarkRunProperties1.Append(fontSizeComplexScript1);
paragraphProperties1.Append(paragraphMarkRunProperties1);
Run run3 = new Run() { RsidRunProperties = "009774CC" };
RunProperties runProperties1 = new RunProperties();
RunFonts runFonts2 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
FontSize fontSize2 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript() { Val = "24" };
VerticalTextAlignment verticalTextAlignment1 = new VerticalTextAlignment() { Val = VerticalPositionValues.Superscript };
runProperties1.Append(runFonts2);
runProperties1.Append(fontSize2);
runProperties1.Append(fontSizeComplexScript2);
runProperties1.Append(verticalTextAlignment1);
Text text1 = new Text();
text1.Text = "1";
run3.Append(runProperties1);
run3.Append(text1);
Run run4 = new Run() { RsidRunProperties = "009774CC" };
RunProperties runProperties2 = new RunProperties();
RunFonts runFonts3 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
runProperties2.Append(runFonts3);
Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
text2.Text = " ";
run4.Append(runProperties2);
run4.Append(text2);
Run run5 = new Run() { RsidRunProperties = "009774CC", RsidRunAddition = "009774CC" };
RunProperties runProperties3 = new RunProperties();
RunFonts runFonts4 = new RunFonts() { AsciiTheme = ThemeFontValues.MinorHighAnsi, HighAnsiTheme = ThemeFontValues.MinorHighAnsi, ComplexScriptTheme = ThemeFontValues.MinorHighAnsi };
FontSize fontSize3 = new FontSize() { Val = "21" };
FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript() { Val = "21" };
runProperties3.Append(runFonts4);
runProperties3.Append(fontSize3);
runProperties3.Append(fontSizeComplexScript3);
Text text3 = new Text();
text3.Text = "This is the foot note text";
run5.Append(runProperties3);
run5.Append(text3);
paragraph3.Append(paragraphProperties1);
paragraph3.Append(run3);
paragraph3.Append(run4);
paragraph3.Append(run5);
footnote3.Append(paragraph3);
footnotes1.Append(footnote1);
footnotes1.Append(footnote2);
footnotes1.Append(footnote3);
part.Footnotes = footnotes1;
}
I managed to add footnotes using the following code.
I hope this helps.
var ms = new MemoryStream();
using (WordprocessingDocument myDoc = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = myDoc.AddMainDocumentPart();
var footPart = mainPart.AddNewPart<FootnotesPart>();
footPart.Footnotes = new Footnotes();
mainPart.Document = new Document();
Body body = new Body();
var p = new Paragraph();
var r = new Run();
var t = new Text("123");
r.Append(t);
p.Append(r);
// ADD THE FOOTNOTE
var footnote = new Footnote();
footnote.Id = 1;
var p2 = new Paragraph();
var r2 = new Run();
var t2 = new Text();
t2.Text = "My FootNote Content";
r2.Append(t2);
p2.Append(r2);
footnote.Append(p2);
footPart.Footnotes.Append(footnote);
// ADD THE FOOTNOTE REFERENCE
var fref = new FootnoteReference();
fref.Id = 1;
var r3 = new Run();
r3.RunProperties = new RunProperties();
var s3 = new VerticalTextAlignment();
s3.Val = VerticalPositionValues.Superscript;
r3.RunProperties.Append(s3);
r3.Append(fref);
p.Append(r3);
body.Append(p);
mainPart.Document.Append(body);
mainPart.Document.Save();
ms.Flush();
}
return ms.ToArray();
I'm not an expert on OpenXML but I think you're missing adding an actual reference to the footnote in the body text, I tweaked your code like this and I now get the footnote in the document. Hope it helps or at least gets you started.
Run run = Para.AppendChild(new Run());
run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("This is main text of the document"));
var footnoteref = new FootnoteReference() { Id = 1 };
run.Append(footnoteref);
How can I style a Run and/or Paragraph to support both RTL and LTR words?
The problem is: I have a complex text which contains both Persian and English words, and I'm trying to create a .docx document using OpenXML SDK. But, the English words, get RTL too. Assume I have this text:
این متن Javad Amiry انگلیسی ست و باید چپ به راست شود.
I'm expecting to place the text in document like this:
But I'm getting this one:
As you can see, English words are vise-versa! Means, while I'm expecting Javad Amiry, I'm getting davaJ yrimA! Do you have any idea to fix that?
The style I'm using is shown below:
var text = "این متن Javad Amiry انگلیسی ست و باید چپ به راست شود.";
var par = new Paragraph();
var pPr = new ParagraphProperties(
new BiDi(),
new Justification { Val = JustificationValues.Both },
new RunFonts {
Ascii = "Arial",
HighAnsi = "Arial",
EastAsia = "Arial",
ComplexScript = "B Mitra",
Hint = FontTypeHintValues.ComplexScript,
},
new FontSize { Val = "24" },
new FontSizeComplexScript { Val = "24" },
new Languages { Bidi = "fa-IR", Val = "en-US", EastAsia = "en-US" }
);
var rPr = new RunProperties(
new RightToLeftText(),
new RunFonts {
Ascii = "Arial",
HighAnsi = "Arial",
EastAsia = "Arial",
ComplexScript = "B Mitra",
Hint = FontTypeHintValues.ComplexScript
},
new FontSize { Val = "24" },
new FontSizeComplexScript { Val = "24" },
new Languages { Bidi = "fa-IR", Val = "en-US", EastAsia = "en-US" },
new BiDi { Val = true }
);
var run = new Run();
run.AppendChild(rPr);
run.AppendChild(new Text(text));
par.AppendChild(pPr);
par.AppendChild(run);
// finally append to the body
body.Append(par);
Thanks in advance.
Well I finally figured-out the problem. The problem was RightToLeftText which I have added to Run. I replaced it with a BiDi and problem solved. Cheers.
How to paginate a word document for example
if there are 10 pages:
page 1 of 10
Page 2 of 10 ...
if there are 15 pages
1 of 15 Page
2 of 15 ...
and so on to generate a dynamic number of pages
It has been three years since you asked your question but maybe I can help other people that are facing this problem.
Here is the code that can paginate a word document.
string documentPath = #"C:\Temp\FooterPOC.docx";
using (WordprocessingDocument package =
WordprocessingDocument.Create(
documentPath, WordprocessingDocumentType.Document))
{
{
MainDocumentPart objMainDocumentPart = package.AddMainDocumentPart();
Document objDocument = new Document();
objMainDocumentPart.Document = objDocument;
Body objBody = new Body();
SectionProperties objSectionProperties = new SectionProperties();
FooterPart objFootPart = objMainDocumentPart.AddNewPart<FooterPart>();
Footer objFooter = new Footer();
objFootPart.Footer = objFooter;
Paragraph objParagraph_1 = new Paragraph();
ParagraphProperties objParagraphProperties = new ParagraphProperties();
ParagraphStyleId objParagraphStyleId = new ParagraphStyleId() { Val = "Footer" };
objParagraphProperties.Append(objParagraphStyleId);
Justification objJustification = new Justification() { Val = JustificationValues.Right };
objParagraphProperties.Append(objJustification);
objParagraph_1.Append(objParagraphProperties);
Run objRun_1 = new Run();
Text objText_1 = new Text() { Space = SpaceProcessingModeValues.Preserve };
objText_1.Text = "Página ";
objRun_1.Append(objText_1);
objParagraph_1.Append(objRun_1);
Run objRun_2 = new Run();
FieldChar objFieldChar_1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
objRun_2.Append(objFieldChar_1);
objParagraph_1.Append(objRun_2);
Run objRun_3 = new Run();
FieldCode objFieldCode_1 = new FieldCode();
objFieldCode_1.Text = "PAGE";
objRun_3.Append(objFieldCode_1);
objParagraph_1.Append(objRun_3);
Run objRun_6 = new Run();
FieldChar objFieldChar_3 = new FieldChar() { FieldCharType = FieldCharValues.End };
objRun_6.Append(objFieldChar_3);
objParagraph_1.Append(objRun_6);
Run objRun_7 = new Run();
Text objText_3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
objText_3.Text = " de ";
objRun_7.Append(objText_3);
objParagraph_1.Append(objRun_7);
Run objRun_8 = new Run();
FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
objRun_8.Append(objFieldChar_4);
objParagraph_1.Append(objRun_8);
Run objRun_9 = new Run();
FieldCode objFieldCode_2 = new FieldCode();
objFieldCode_2.Text = "NUMPAGES";
objRun_9.Append(objFieldCode_2);
objParagraph_1.Append(objRun_9);
Run objRun_12 = new Run();
FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
objRun_12.Append(objFieldChar_6);
objParagraph_1.Append(objRun_12);
objFooter.Append(objParagraph_1);
string strFootrID = objMainDocumentPart.GetIdOfPart(objFootPart);
FooterReference objFooterReference = new FooterReference()
{
Type = HeaderFooterValues.Default,
Id = strFootrID
};
objSectionProperties.Append(objFooterReference);
objBody.Append(objSectionProperties);
objMainDocumentPart.Document.Append(objBody);
}
}
I found this code here. It was a little bit buggy but it helped me a lot!
There were a few lines that i thought it was unnecessary so i removed it and worked great, but i'm only a newbie in openXML so maybe they were in fact necessary.
Cheers!
The Open Xml SDK does NOT provide application behaviors such as layout (ex. pagination of WordprocessingML documents) or recalculation functionality. You can read more # http://blogs.msdn.com/b/brian_jones/archive/2008/10/06/open-xml-format-sdk-2-0.aspx
I am trying top create a word file with the header and footer and footer must have a Image can any one help me to do that.
I am using Open XML to create word file .
You can try this. You need to create a DocumentResource (Item->Add new) and associate an image.
private static Footer BuildFooter(FooterPart hp, string title)
{
ImagePart ip = hp.AddImagePart(ImagePartType.Jpeg);
string imageRelationshipID = hp.GetIdOfPart(ip);
using (Stream imgStream = ip.GetStream())
{
System.Drawing.Bitmap logo = DocumentResources._default;
logo.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Footer h = new Footer();
DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
Run r = new Run();
Drawing drawing = BuildImage(imageRelationshipID, "_default.jpg", 200, 30);
r.Append(drawing);
p.Append(r);
r = new Run();
RunProperties rPr = new RunProperties();
TabChar tab = new TabChar();
Bold b = new Bold();
Color color = new Color { Val = "000000" };
DocumentFormat.OpenXml.Wordprocessing.FontSize sz = new DocumentFormat.OpenXml.Wordprocessing.FontSize {Val = Convert.ToString("40")};
Text t = new Text { Text = title };
rPr.Append(b);
rPr.Append(color);
rPr.Append(sz);
r.Append(rPr);
r.Append(tab);
r.Append(t);
p.Append(r);
h.Append(p);
return h;
}
and to build image
private static Drawing BuildImage(string imageRelationshipID, string imageName, int pixelWidth, int pixelHeight)
{
int emuWidth = (int)(pixelWidth * EMU_PER_PIXEL);
int emuHeight = (int)(pixelHeight * EMU_PER_PIXEL);
Drawing drawing = new Drawing();
d.Wordprocessing.Inline inline = new d.Wordprocessing.Inline { DistanceFromTop = 0, DistanceFromBottom = 0, DistanceFromLeft = 0, DistanceFromRight = 0 };
d.Wordprocessing.Anchor anchor = new d.Wordprocessing.Anchor();
d.Wordprocessing.SimplePosition simplePos = new d.Wordprocessing.SimplePosition { X = 0, Y = 0 };
d.Wordprocessing.Extent extent = new d.Wordprocessing.Extent { Cx = emuWidth, Cy = emuHeight };
d.Wordprocessing.DocProperties docPr = new d.Wordprocessing.DocProperties { Id = 1, Name = imageName };
d.Graphic graphic = new d.Graphic();
d.GraphicData graphicData = new d.GraphicData { Uri = GRAPHIC_DATA_URI };
d.Pictures.Picture pic = new d.Pictures.Picture();
d.Pictures.NonVisualPictureProperties nvPicPr = new d.Pictures.NonVisualPictureProperties();
d.Pictures.NonVisualDrawingProperties cNvPr = new d.Pictures.NonVisualDrawingProperties { Id = 2, Name = imageName };
d.Pictures.NonVisualPictureDrawingProperties cNvPicPr = new d.Pictures.NonVisualPictureDrawingProperties();
d.Pictures.BlipFill blipFill = new d.Pictures.BlipFill();
d.Blip blip = new d.Blip { Embed = imageRelationshipID };
d.Stretch stretch = new d.Stretch();
d.FillRectangle fillRect = new d.FillRectangle();
d.Pictures.ShapeProperties spPr = new d.Pictures.ShapeProperties();
d.Transform2D xfrm = new d.Transform2D();
d.Offset off = new d.Offset { X = 0, Y = 0 };
d.Extents ext = new d.Extents { Cx = emuWidth, Cy = emuHeight };
d.PresetGeometry prstGeom = new d.PresetGeometry { Preset = d.ShapeTypeValues.Rectangle };
d.AdjustValueList avLst = new d.AdjustValueList();
xfrm.Append(off);
xfrm.Append(ext);
prstGeom.Append(avLst);
stretch.Append(fillRect);
spPr.Append(xfrm);
spPr.Append(prstGeom);
blipFill.Append(blip);
blipFill.Append(stretch);
nvPicPr.Append(cNvPr);
nvPicPr.Append(cNvPicPr);
pic.Append(nvPicPr);
pic.Append(blipFill);
pic.Append(spPr);
graphicData.Append(pic);
graphic.Append(graphicData);
inline.Append(extent);
inline.Append(docPr);
inline.Append(graphic);
drawing.Append(inline);
return drawing;
}
To call those functions, in your function that build the document
FooterPart hp = mp.AddNewPart<FooterPart>();
string headerRelationshipID = mp.GetIdOfPart(hp);
SectionProperties sectPr = new SectionProperties();
FooterReference footerReference = new FooterReference();
FooterReference.Id = footerRelationshipID;
FooterReference.Type = HeaderFooterValues.Default;
sectPr.Append(footerReference);
b.Append(sectPr);
d.Append(b);
hp.Footer = BuildFooter(hp, "My Test");