Skip to content

Instantly share code, notes, and snippets.

@mcw0933
Created May 8, 2013 20:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcw0933/5543526 to your computer and use it in GitHub Desktop.
Save mcw0933/5543526 to your computer and use it in GitHub Desktop.
Getting the first page of a fixed document sequence as a reference page to know how to set page orientation. Assumes that all pages in the document are the same size and same orientation as page 1.
/// <summary>
/// Gets the PageOrientation of the first page of a fixed document sequence, based on that page's dimensions.
/// </summary>
/// <param name="docSeq">The fixed document sequence.</param>
/// <returns>
/// If the first page could not be found, returns Unknown.
/// Returns Portrait when the page width is less than the height.
/// Otherwise (width is greater than OR EQUAL), returns Landscape.
/// </returns>
private static PageOrientation GetPageOrientationOfFirstPageOfFixedDocSeq(FixedDocumentSequence docSeq) {
PageOrientation orientation = PageOrientation.Unknown;
FixedPage firstPage = GetFirstPageOfFixedDocSeq(docSeq);
if (firstPage != null) {
orientation = (firstPage.Width >= firstPage.Height) ? PageOrientation.Landscape : PageOrientation.Portrait;
}
return orientation;
}
/// <summary>
/// Gets the first fixed document in a fixed document sequence, or null.
/// </summary>
/// <param name="docSeq">The fixed document sequence</param>
/// <returns>The first fixed document, or null.</returns>
private static FixedDocument GetFirstDocumentOfFixedDocSeq(FixedDocumentSequence docSeq)
{
FixedDocument firstDoc = null;
if (docSeq != null && docSeq.References != null && docSeq.References.Count > 0)
{
DocumentReference firstDocRef = docSeq.References[0];
firstDoc = firstDocRef.GetDocument(true);
}
return firstDoc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment