

- #How change orientation of one page in word 2013 how to#
- #How change orientation of one page in word 2013 install#
- #How change orientation of one page in word 2013 update#
- #How change orientation of one page in word 2013 code#
SectPr.Descendants(Of PageMargin).FirstOrDefault()Īfter all the modifications, the code determines whether the document PgMar.Bottom = new Int32Value((int)right) Margin settings, as shown in the following code. TheĬode must convert between the two types of values as it rotates the Left and Right properties are unsigned values. The margins by 90 degrees-some printers rotate the margins by 270ĭegrees instead and you could modify the code to take that into account.Īlso be aware that the Top and Bottom properties of the PageMargin object are signed values, and the If theĮlement exists, the code rotates the margins. To do so, the code retrieves a reference to the PageMargin element for the section. If the page orientation has changed, the code must rotate the margins to The next step in the sample procedure handles margins for the section. ' Changing the orientation is not enough. Changing the orientation is not enough. The first task is easy-theįollowing code just swaps the page height and width, storing the values If newOrientation ThenĪt this point in the code, the page orientation may have changed. New EnumValue(Of PageOrientationValues)(newOrientation) If newOrientation PageOrientationValues.Portrait Then If (newOrientation != PageOrientationValues.Portrait) If the code must create the Orient property, it must also create the value to store in the property, as a new EnumValue instance, supplying the new orientation in the EnumValue constructor. It uses the documentChanged flag to determine whether it must (The code uses the pageOrientationChanged flag to determine whether it PageOrientationChanged and the documentChanged flags. Method, the code sets the Value property of If the Orient property already exists, and its valueĭiffers from the new orientation value supplied as a parameter to the
#How change orientation of one page in word 2013 update#
If the property does not exist, and the new orientation is Portrait, theĬode will not update the page. That case, retrieving the property returns a null reference. Of Open XML elements, the property or attribute might not exist yet. The next block of code first checks whether the Orient property of the PageSize element exists. SectPr.Descendants(Of PageSize).FirstOrDefault PageSize pgSz = sectPr.Descendants().FirstOrDefault() įor Each sectPr As SectionProperties In sectionsĭim pageOrientationChanged As Boolean = False foreach (SectionProperties sectPr in sections) If the reference is not null, the code updates the orientation as required.

(If the new orientation matches the original orientation, the code will not update the page.) The code continues by retrieving a reference to the first PageSize descendant of the SectionProperties element. For each section, the code initializes a variable that tracks whether the page orientation for the section was changed so the code can update the page size and margins. The next block of code iterates through all the sections in the collection of SectionProperties elements. WordprocessingDocument.Open(fileName, True)ĭim sections = (Of SectionProperties)() WordprocessingDocument.Open(fileName, true)) Later code will use this collection to set the orientation forĮach section in turn. The code retrieves a reference to the mainĭocument part, and then uses that reference to retrieve a collection ofĪll of the descendants of type SectionProperties within the content of theĭocument. The document has changed (so that it can save the document later, if theĭocument has changed). The code maintains a Boolean variable that tracks whether True to indicate that the document shouldīe read/write. The following code first opens the document by using the Open method and sets the isEditable parameter to Theįollowing code shows an example method call. Method, pass a string that contains the name of the file to convert. Calling the Sample SetPrintOrientation Method The width, height, and margins for each section. In addition, the code must manually update The section's current print orientation, the code modifies the print String fileName, PageOrientationValues newOrientation)īyVal newOrientation As PageOrientationValues)įor each section in the document, if the new orientation differs from The following code shows the SetPrintOrientation method. Modify (string) and the new print orientation ( PageOrientationValues). Method accepts two parameters that indicate the name of the document to To change the print orientation of a word processing document. You can use the SetPrintOrientation method Must explicitly reference the following assemblies in your project:ĭocumentFormat.OpenXml (installed by the Open XML SDK)ĭirectives or Imports statements to compile
#How change orientation of one page in word 2013 install#
To use the sample code in this topic, you must install the Open XML SDK SetPrintOrientation method to illustrate this task.

Office to programmatically set the print orientation of a Microsoft WordĢ010 or Microsoft Word 2013 document.
#How change orientation of one page in word 2013 how to#
This topic shows how to use the classes in the Open XML SDK 2.5 for
