ComponentOne Word for UWP
Working with Word for UWP / Advanced Level Working / Creating Word Document with different paper sizes
In This Topic
    Creating Word Document with different paper sizes
    In This Topic

    Word for UWP gives you the flexibility to create a word document with different paper sizes. You can use PaperKind enum to specify any of the available standard paper sizes.

    Note that a class named WordUtils is used in the code given below. It is available in the product sample located at the following location on your system:
    Documents\ComponentOne Samples\UWP\WordSample
    You can use these classes in your application from the mentioned location.

    The implementation of PaperKind enum is given in the following code:

    ' create one page with each paper size
    Dim firstPage As Boolean = True
    For Each pk As PaperKind In [Enum].GetValues(GetType(PaperKind))
            ' Silverlight doesn't have Enum.GetValues
            'PaperKind pk = fi;
    
            ' skip custom size
            If pk = PaperKind.[Custom] Then
                    Continue For
            End If
    
            ' add new page for every page after the first one
            If Not firstPage Then
                    word.PageBreak()
            End If
            firstPage = False
    
            ' set paper kind and orientation
            'word.PaperKind = pk;
            word.Landscape = Not word.Landscape
    
            ' draw some content on the page
            rc = WordUtils.PageRectangle(word)
            rc = WordUtils.Inflate(rc, -6, -6)
            'string text = string.Format(Strings.StringFormatTwoArg, word.PaperKind, word.Landscape);
            Dim text As String = String.Format(Strings.StringFormatTwoArg, pk, word.Landscape)
            word.DrawString(text, font, Colors.Black, rc, sf)
            word.DrawRectangle(Colors.Black, rc)
    Next
    
    // create one page with each paper size
    bool firstPage = true;
    foreach(PaperKind pk in Enum.GetValues(typeof(PaperKind))) {
      // Silverlight doesn't have Enum.GetValues
      //PaperKind pk = fi;
    
      // skip custom size
      if (pk == PaperKind.Custom) continue;
    
      // add new page for every page after the first one
      if (!firstPage) word.PageBreak();
      firstPage = false;
    
      // set paper kind and orientation
      //word.PaperKind = pk;
      word.Landscape = !word.Landscape;
    
      // draw some content on the page
      rc = WordUtils.PageRectangle(word);
      rc = WordUtils.Inflate(rc, -6, -6);
      //string text = string.Format(Strings.StringFormatTwoArg, word.PaperKind, word.Landscape);
      string text = string.Format(Strings.StringFormatTwoArg, pk, word.Landscape);
      word.DrawString(text, font, Colors.Black, rc, sf);
      word.DrawRectangle(Colors.Black, rc);
    }