none
Shape in second page RRS feed

  • Question

  • Hi, can you help me? I have document in word. I need draw a shape in second page with programming, but as result shape founded in first page and third and go on... I drawing shape over the big table, that fill page.

    may be anybody know why word have this bihavior?

    Thursday, August 2, 2012 3:26 AM

All replies

  • Hi, can you help me? I have document in word. I need draw a shape in second page with programming, but as result shape founded in first page and third and go on... I drawing shape over the big table, that fill page.

    may be anybody know why word have this bihavior?

    Wednesday, August 1, 2012 3:06 AM
  • It's tricky accessing sections of a Word document based on page.

    I don't know how to complete that task, but I'm posting mainly to suggest you repeat your question here, in the Word for Developers forum. It is more focused towards your task.

    • Edited by JosephFox Wednesday, August 1, 2012 10:11 PM
    Wednesday, August 1, 2012 10:10 PM
  • thank you!
    • Edited by Dakiny Thursday, August 2, 2012 8:04 AM
    Thursday, August 2, 2012 3:27 AM
  • Hi Dakiny,

    Thanks for posting in the MSDN Forum.

    Based on your issue, could you please share the snippet of drawing the shape here? It's beneficial for us to reproduce your issue and trouble shoot for you.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us


    Friday, August 3, 2012 6:20 AM
    Moderator
  • It is not at all clear where you want the picture to go - you mention both a table and filling the page.

    The following code puts a picture into the first cell on page 2:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim Rng As Range, i As Long, ImageName As String
    ImageName = "C:\Users\" & Environ("UserName") & "\Documents\image.jpeg"
    With ActiveDocument
      Set Rng = ActiveDocument.GoTo(What:=wdGoToPage, Name:="2")
      Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
      Set Rng = Rng.Cells(1).Range
      Rng.Collapse
      .InlineShapes.AddPicture FileName:=ImageName, SaveWithDocument:=True, Range:=Rng
    End With
    Set Rng = Nothing
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, August 3, 2012 6:53 AM
  • it is function on c# language

     void DrawingTextIntoDocument(Document doc, ExportPageChangeDTO st, ExportNumberChangeDTO change, ExportDataSpecificationId data)
            {
                Range r, rr = null;
                object EndOfPage = @"\page";
                object wdWhat = WdGoToItem.wdGoToPage;
                object wdWich = WdGoToDirection.wdGoToNext;
                object count = (object)1;
                int TotalPages, i;
                TotalPages = doc.ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing);
                object move = WdGoToItem.wdGoToLine;
                object how = WdGoToDirection.wdGoToNext;
    
                doc.Application.Windows.get_Item(ref count).View.ShowBookmarks = true;
    
               
                for (i = 1; i <= TotalPages; i++)
                {
                    r = doc.Bookmarks.get_Item(ref EndOfPage).Range;
                    
                    if (i > 1)
                    {
                        try
                        {
                            if (i == TotalPages) DrawindAgreeTable(doc, true, 0);
                            else DrawindAgreeTable(doc, false, 0);
                        }
                        catch
                        {
                            doc.ActiveWindow.Selection.GoTo(ref move, ref how, ref count, ref oMissing);
                            if (i == TotalPages) DrawindAgreeTable(doc, true, cursor_y1 - cursor_y);
                            else DrawindAgreeTable(doc, false, cursor_y1 - cursor_y);
                        }
                        foreach (string p in st.ListChangedPages)
                        {
                            if (i.ToString() == p)
                            {
                                listCoordinate.ForEach(x =>
                                {
                                    if (p == x.Key)
                                    {
                                        var pointer = doc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeParallelogram, 20 + (change.NumberChange - 1) * 22, x.Value, 22, 16, ref oMissing);
                                        pointer.TextFrame.TextRange.Text = change.NumberChangeArchive.ToString();// "1";
                                        pointer.TextFrame.TextRange.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                                        pointer.TextFrame.TextRange.Orientation = WdTextOrientation.wdTextOrientationHorizontal;
                                    }
                                });
    
                                int cnt = CountRecoderInPage(data, p);
                                DrawStampChange(doc, cnt, change.NumberChangeArchive, st.NumberDoc, DateTime.Now.Date.ToString("d").Substring(0, 5));
                                break;
                            }
                        }
                       
                    }
                    else
                    {
                        rr = r;
                    }
    
                    r = r.GoTo(ref wdWhat, ref wdWich, ref count, ref oMissing);
                    r.Select();
                }
    
            }

    where "DrawingAgreeTable" is function for drawing a group shape. This shape i'm draw on second page, but it move up on firts page and then repeat on all pages in document

    Friday, August 3, 2012 9:15 AM
  • Hi Dakiny,

    I'm sorry but I cann't reproduce your function in my project. Obviously, the types of variable ExportPageChangeDTO,ExportNumberChangeDTO and ExportDataSpecificationId are unknown. So, if you feel convenient, please share all the code of your issue here or upload your project in the SkyDrive.

    Have a good day.


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us


    Monday, August 6, 2012 9:13 AM
    Moderator
  • OK, may be that all right.

     void DrawingTextIntoDocument(Document doc)
            {
                Range r, rr = null;
                object EndOfPage = @"\page";
                object wdWhat = WdGoToItem.wdGoToPage;
                object wdWich = WdGoToDirection.wdGoToNext;
                object count = (object)1;
                int TotalPages, i;
                TotalPages = doc.ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing);
                object move = WdGoToItem.wdGoToLine;
                object how = WdGoToDirection.wdGoToNext;
    
                doc.Application.Windows.get_Item(ref count).View.ShowBookmarks = true;
    
               
                for (i = 1; i <= TotalPages; i++)
                {
                    r = doc.Bookmarks.get_Item(ref EndOfPage).Range;
                    
                    if (i > 1)
                    {
                        try
                        {
                            if (i == TotalPages) DrawindAgreeTable(doc, true, 0);
                            else DrawindAgreeTable(doc, false, 0);
                        }
                        catch
                        {
                            doc.ActiveWindow.Selection.GoTo(ref move, ref how, ref count, ref oMissing);
                            if (i == TotalPages) DrawindAgreeTable(doc, true, cursor_y1 - cursor_y);
                            else DrawindAgreeTable(doc, false, 0);
                        }
                        foreach (string p in st.ListChangedPages)
                        {
                            if (i.ToString() == p)
                            {
                                listCoordinate.ForEach(x =>
                                {
                                    if (p == x.Key)
                                    {
                                        var pointer = doc.Shapes.AddShape((int)Microsoft.Office.Core.MsoAutoShapeType.msoShapeParallelogram, 20 + 22, x.Value, 22, 16, ref oMissing);
                                        pointer.TextFrame.TextRange.Text = "1";
                                        pointer.TextFrame.TextRange.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                                        pointer.TextFrame.TextRange.Orientation = WdTextOrientation.wdTextOrientationHorizontal;
                                    }
                                });
    
                                int cnt = CountRecoderInPage(data, p);
                                DrawStampChange(doc, 1, 1, "222-12", DateTime.Now.Date.ToString("d").Substring(0, 5));
                                break;
                            }
                        }
                       
                    }
                    else
                    {
                        rr = r;
                    }
    
                    r = r.GoTo(ref wdWhat, ref wdWich, ref count, ref oMissing);
                    r.Select();
                }
    
            }

    i'm remove all unnecessary

    Tuesday, August 7, 2012 3:37 AM
  • Hi Dakiny,

    Thanks for your quick reply.

    However, the code in your last post is still not able to be reproduced due to the missing DrawingAgreeTable function. I think it is a customized function to draw the shape, so the partial snippet doesn't work. Much helpful if you would amend your code and make it run properly. Thanks.

    Best Regards,


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 7, 2012 6:21 AM
    Moderator