Niko.K Niko.K - 1 year ago 71
C# Question

Missing Page in WordDoc

I am adding images regarding mount of "images" taken into my word as so called InlineShapes. But I have the issue that 8 images are created but only 7 are "uploaded" in the word file why so ever.

int pagecount = document.PageCount;
//With the int pagecount we can create as may screenshots as there are pages in the document
for (int index = 1; index < pagecount; index++)
application.Selection.InlineShapes.AddPicture(outputFileName + index + ".jpg");

And yes my page count is also 8.

foreach (Microsoft.Office.Interop.Word.InlineShape inline in doc.InlineShapes)

//Special sacling is done or landscape docs as well as portrait doumcnets
if (inline.Height < inline.Width)
doc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
inline.ScaleWidth = 90;
inline.ScaleHeight = 90;

Here is the scaling done for each image when inserted into the word file and this loop "actives" it self only seven time but why ?

Answer Source

Your pageCount is 8 but you are iterating from index 1 until it is greater than or equals to pageCount.

To fix this either start from index = 0 or until index <= pagecount whichever makes sense from a logical point of view. So either:

for (int index = 0; index < pagecount; index++)


for (int index = 1; index <= pagecount; index++)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download