Insert image on first page of word documentHow do you display code snippets in MS Word preserving format and syntax highlighting?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?Relationship error when trying to embed and image into a Word documentOpenXMLSDk: Insert Images Corrupted the documentOpenXML insert comment reply into word document C#Insert List<string> into word documentAdd image with text in header of every page in pdf file using itextsharpInsert picture to header of Word document with OpenXMLAdd image to Word document, like drag and dropOpenXML How to insert an object with an image in a Word document

Why teach C using scanf without talking about command line arguments?

Is it possible to breed neanderthals through selective breeding?

May I use a railway velocipede on used British railways?

Is straight-up writing someone's opinions telling?

Did Hitler say this quote about homeschooling?

What are the basics of commands in Minecraft Java Edition?

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

Necroskitter and creatures dying because of placing -1/-1 counters

Why did Fury respond that way?

Why were these characters absent in Spider-Man: Far From Home?

Why can't I hear fret buzz through the amp?

Whipping heavy cream with melted chocolate

How fast does a character need to move to be effectively invisible?

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

The most secure way to handle someone forgetting to verify their account?

Which GPUs to get for Mathematical Optimization (if any)?

Cauchy reals and Dedekind reals satisfy "the same mathematical theorems"

Change Opacity of Style

Practical example in using (homotopy) type theory

I have found a mistake on someone's code published online: what is the protocol?

What happens if a company buys back all of its shares?

Software need db owner permission to master database (sql2016)

Which modern firearm should a time traveler bring to be easily reproducible for a historic civilization?

An entire function all whose forward orbits are bounded



Insert image on first page of word document


How do you display code snippets in MS Word preserving format and syntax highlighting?How do I remedy the “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?Relationship error when trying to embed and image into a Word documentOpenXMLSDk: Insert Images Corrupted the documentOpenXML insert comment reply into word document C#Insert List<string> into word documentAdd image with text in header of every page in pdf file using itextsharpInsert picture to header of Word document with OpenXMLAdd image to Word document, like drag and dropOpenXML How to insert an object with an image in a Word document






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am new to Open XML. I want to insert an image at the bottom-left of the word(docx) document using Open XML sdk.



I have tried understanding the code provided by Microsoft to insert the image but it appends the image on the last page of the word document.



public static void InsertAPicture(string document, string fileName)

using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true))

MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

using (FileStream stream = new FileStream(fileName, FileMode.Open))

imagePart.FeedData(stream);

AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));



private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)

// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() Cx = 990000L, Cy = 792000L ,
new DW.EffectExtent()

LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
,
new DW.DocProperties()

Id = (UInt32Value)1U,
Name = "Picture 1"
,
new DW.NonVisualGraphicFrameDrawingProperties(
new A.GraphicFrameLocks() NoChangeAspect = true ),
new A.Graphic(
new A.GraphicData(
new PIC.Picture(
new PIC.NonVisualPictureProperties(
new PIC.NonVisualDrawingProperties()

Id = (UInt32Value)0U,
Name = "New Bitmap Image.jpg"
,
new PIC.NonVisualPictureDrawingProperties()),
new PIC.BlipFill(
new A.Blip(
new A.BlipExtensionList(
new A.BlipExtension()

Uri =
"28A0092B-C50C-407E-A947-70E740481C1C"
)
)

Embed = relationshipId,
CompressionState = A.BlipCompressionValues.Print
,
new A.Stretch(
new A.FillRectangle())),
new PIC.ShapeProperties(
new A.Transform2D(
new A.Offset() X = 0L, Y = 0L ,
new A.Extents() Cx = 990000L, Cy = 792000L ),
new A.PresetGeometry(
new A.AdjustValueList()
) Preset = A.ShapeTypeValues.Rectangle ))
) Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" )
)

DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U,
EditId = "50D07946"
);

// Append the reference to body, the element should be in a Run.
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));



I want the provided images to be inserted at the bottom left of the first page of word document.










share|improve this question
























  • It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

    – Cindy Meister
    Mar 26 at 22:16

















0















I am new to Open XML. I want to insert an image at the bottom-left of the word(docx) document using Open XML sdk.



I have tried understanding the code provided by Microsoft to insert the image but it appends the image on the last page of the word document.



public static void InsertAPicture(string document, string fileName)

using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true))

MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

using (FileStream stream = new FileStream(fileName, FileMode.Open))

imagePart.FeedData(stream);

AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));



private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)

// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() Cx = 990000L, Cy = 792000L ,
new DW.EffectExtent()

LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
,
new DW.DocProperties()

Id = (UInt32Value)1U,
Name = "Picture 1"
,
new DW.NonVisualGraphicFrameDrawingProperties(
new A.GraphicFrameLocks() NoChangeAspect = true ),
new A.Graphic(
new A.GraphicData(
new PIC.Picture(
new PIC.NonVisualPictureProperties(
new PIC.NonVisualDrawingProperties()

Id = (UInt32Value)0U,
Name = "New Bitmap Image.jpg"
,
new PIC.NonVisualPictureDrawingProperties()),
new PIC.BlipFill(
new A.Blip(
new A.BlipExtensionList(
new A.BlipExtension()

Uri =
"28A0092B-C50C-407E-A947-70E740481C1C"
)
)

Embed = relationshipId,
CompressionState = A.BlipCompressionValues.Print
,
new A.Stretch(
new A.FillRectangle())),
new PIC.ShapeProperties(
new A.Transform2D(
new A.Offset() X = 0L, Y = 0L ,
new A.Extents() Cx = 990000L, Cy = 792000L ),
new A.PresetGeometry(
new A.AdjustValueList()
) Preset = A.ShapeTypeValues.Rectangle ))
) Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" )
)

DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U,
EditId = "50D07946"
);

// Append the reference to body, the element should be in a Run.
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));



I want the provided images to be inserted at the bottom left of the first page of word document.










share|improve this question
























  • It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

    – Cindy Meister
    Mar 26 at 22:16













0












0








0








I am new to Open XML. I want to insert an image at the bottom-left of the word(docx) document using Open XML sdk.



I have tried understanding the code provided by Microsoft to insert the image but it appends the image on the last page of the word document.



public static void InsertAPicture(string document, string fileName)

using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true))

MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

using (FileStream stream = new FileStream(fileName, FileMode.Open))

imagePart.FeedData(stream);

AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));



private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)

// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() Cx = 990000L, Cy = 792000L ,
new DW.EffectExtent()

LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
,
new DW.DocProperties()

Id = (UInt32Value)1U,
Name = "Picture 1"
,
new DW.NonVisualGraphicFrameDrawingProperties(
new A.GraphicFrameLocks() NoChangeAspect = true ),
new A.Graphic(
new A.GraphicData(
new PIC.Picture(
new PIC.NonVisualPictureProperties(
new PIC.NonVisualDrawingProperties()

Id = (UInt32Value)0U,
Name = "New Bitmap Image.jpg"
,
new PIC.NonVisualPictureDrawingProperties()),
new PIC.BlipFill(
new A.Blip(
new A.BlipExtensionList(
new A.BlipExtension()

Uri =
"28A0092B-C50C-407E-A947-70E740481C1C"
)
)

Embed = relationshipId,
CompressionState = A.BlipCompressionValues.Print
,
new A.Stretch(
new A.FillRectangle())),
new PIC.ShapeProperties(
new A.Transform2D(
new A.Offset() X = 0L, Y = 0L ,
new A.Extents() Cx = 990000L, Cy = 792000L ),
new A.PresetGeometry(
new A.AdjustValueList()
) Preset = A.ShapeTypeValues.Rectangle ))
) Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" )
)

DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U,
EditId = "50D07946"
);

// Append the reference to body, the element should be in a Run.
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));



I want the provided images to be inserted at the bottom left of the first page of word document.










share|improve this question
















I am new to Open XML. I want to insert an image at the bottom-left of the word(docx) document using Open XML sdk.



I have tried understanding the code provided by Microsoft to insert the image but it appends the image on the last page of the word document.



public static void InsertAPicture(string document, string fileName)

using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true))

MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;

ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

using (FileStream stream = new FileStream(fileName, FileMode.Open))

imagePart.FeedData(stream);

AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart));



private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)

// Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() Cx = 990000L, Cy = 792000L ,
new DW.EffectExtent()

LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
,
new DW.DocProperties()

Id = (UInt32Value)1U,
Name = "Picture 1"
,
new DW.NonVisualGraphicFrameDrawingProperties(
new A.GraphicFrameLocks() NoChangeAspect = true ),
new A.Graphic(
new A.GraphicData(
new PIC.Picture(
new PIC.NonVisualPictureProperties(
new PIC.NonVisualDrawingProperties()

Id = (UInt32Value)0U,
Name = "New Bitmap Image.jpg"
,
new PIC.NonVisualPictureDrawingProperties()),
new PIC.BlipFill(
new A.Blip(
new A.BlipExtensionList(
new A.BlipExtension()

Uri =
"28A0092B-C50C-407E-A947-70E740481C1C"
)
)

Embed = relationshipId,
CompressionState = A.BlipCompressionValues.Print
,
new A.Stretch(
new A.FillRectangle())),
new PIC.ShapeProperties(
new A.Transform2D(
new A.Offset() X = 0L, Y = 0L ,
new A.Extents() Cx = 990000L, Cy = 792000L ),
new A.PresetGeometry(
new A.AdjustValueList()
) Preset = A.ShapeTypeValues.Rectangle ))
) Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" )
)

DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U,
EditId = "50D07946"
);

// Append the reference to body, the element should be in a Run.
wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element)));



I want the provided images to be inserted at the bottom left of the first page of word document.







c# ms-word openxml openxml-sdk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 18:50









FortyTwo

1,8323 gold badges15 silver badges25 bronze badges




1,8323 gold badges15 silver badges25 bronze badges










asked Mar 26 at 9:55









Shivam SinghalShivam Singhal

11 bronze badge




11 bronze badge












  • It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

    – Cindy Meister
    Mar 26 at 22:16

















  • It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

    – Cindy Meister
    Mar 26 at 22:16
















It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

– Cindy Meister
Mar 26 at 22:16





It is not possible to determine on which page content is located using Open XML. This works directly with the unopened file. Page breaks generated by Word automatically are not stored in the file, they're only created when a document is open in the Word interface, on-the-fly. A possibility would be to create a "Different First Page" footer and put the graphic in that. Then you'd be sure it's on the first page... I suggest learning how that works in the Word application, as an end-user. Generate a sample document, then open it in the Open XML SDK Productivity Tool to get the basic code.

– Cindy Meister
Mar 26 at 22:16












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354197%2finsert-image-on-first-page-of-word-document%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354197%2finsert-image-on-first-page-of-word-document%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript