Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion dotnet/src/webdriver/PrintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PrintOptions
private const double DefaultPageHeight = 21.59;
private const double DefaultPageWidth = 27.94;
private const double CentimetersPerInch = 2.54;

private double scale = 1.0;
private PageSize pageSize = new PageSize();
private Margins margins = new Margins();
Expand Down Expand Up @@ -259,6 +259,30 @@ public class PageSize
private double height = DefaultPageHeight;
private double width = DefaultPageWidth;

/// <summary>
/// Represents the A4 paper size.
/// Width: 21.0 cm, Height: 29.7 cm
/// </summary>
public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm

/// <summary>
/// Represents the Legal paper size.
/// Width: 21.59 cm, Height: 35.56 cm
/// </summary>
public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm

/// <summary>
/// Represents the Letter paper size.
/// Width: 21.59 cm, Height: 27.94 cm
/// </summary>
public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm

/// <summary>
/// Represents the Tabloid paper size.
/// Width: 27.94 cm, Height: 43.18 cm
/// </summary>
public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm

/// <summary>
/// Gets or sets the height of each page in centimeters.
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions dotnet/test/common/PrintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,40 @@ public void MarginsCannotHaveNegativeValues()
Assert.That(() => new PrintOptions.Margins { Left = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf<ArgumentOutOfRangeException>());
}

[Test]
public void CanSetPredefinedPageSizes()
{
var options = new PrintOptions();

options.PageDimensions = PrintOptions.PageSize.A4;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.A4.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.A4.Height));

options.PageDimensions = PrintOptions.PageSize.Legal;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Legal.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Legal.Height));

options.PageDimensions = PrintOptions.PageSize.Letter;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Letter.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Letter.Height));

options.PageDimensions = PrintOptions.PageSize.Tabloid;
Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Tabloid.Width));
Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Tabloid.Height));
}

[Test]
public void CanSetCustomPageSize()
{
var options = new PrintOptions();
var customPageSize = new PrintOptions.PageSize { Width = 25.0, Height = 30.0 };

options.PageDimensions = customPageSize;

Assert.That(options.PageDimensions.Width, Is.EqualTo(25.0));
Assert.That(options.PageDimensions.Height, Is.EqualTo(30.0));
}

}
}