Skip to content

Commit

Permalink
fix(page): fix pdf PaperFormat (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Oct 10, 2020
1 parent ee15c39 commit 708a02f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/Common/PackageInfo.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>0.142.1</PackageVersion>
<PackageVersion>0.142.2</PackageVersion>
<AssemblyVersion>$(PackageVersion)</AssemblyVersion>
<ReleaseVersion>$(PackageVersion)</ReleaseVersion>
<FileVersion>$(PackageVersion)</FileVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/PdfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task ShouldBeAbleToSaveFile()
{
fileInfo.Delete();
}
await Page.GetPdfAsync(outputFile);
await Page.GetPdfAsync(outputFile, format: PaperFormat.Letter);
fileInfo = new FileInfo(outputFile);
Assert.True(new FileInfo(outputFile).Length > 0);
if (fileInfo.Exists)
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp/IPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ Task<byte[]> GetPdfAsync(
bool printBackground = false,
bool landscape = false,
string pageRanges = "",
PaperFormat format = null,
PaperFormat? format = null,
string width = null,
string height = null,
Margin margin = null,
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp/Margin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace PlaywrightSharp
{
/// <summary>
/// Margin options used in <see cref="IPage.GetPdfAsync(string, decimal, bool, string, string, bool, bool, string, PaperFormat, string, string, Margin, bool)"/>.
/// Margin options used in <see cref="IPage.GetPdfAsync(string, decimal, bool, string, string, bool, bool, string, PaperFormat?, string, string, Margin, bool)"/>.
/// </summary>
public class Margin : IEquatable<Margin>
{
Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public async Task<byte[]> GetPdfAsync(
bool printBackground = false,
bool landscape = false,
string pageRanges = "",
PaperFormat format = null,
PaperFormat? format = null,
string width = null,
string height = null,
Margin margin = null,
Expand Down
85 changes: 13 additions & 72 deletions src/PlaywrightSharp/PaperFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,62 @@ namespace PlaywrightSharp
/// <summary>
/// Paper format.
/// </summary>
/// <seealso cref="IPage.GetPdfAsync(string, decimal, bool, string, string, bool, bool, string, PaperFormat, string, string, Margin, bool)"/>
public class PaperFormat : IEquatable<PaperFormat>
/// <seealso cref="IPage.GetPdfAsync(string, decimal, bool, string, string, bool, bool, string, PaperFormat?, string, string, Margin, bool)"/>
public enum PaperFormat
{
/// <summary>
/// Initializes a new instance of the <see cref="PaperFormat"/> class.
/// </summary>
/// <param name="width">Page width in inches.</param>
/// <param name="height">Page height in inches.</param>
public PaperFormat(decimal width, decimal height)
{
Width = width;
Height = height;
}

/// <summary>
/// Letter: 8.5 inches x 11 inches.
/// </summary>
public static PaperFormat Letter => new PaperFormat(8.5m, 11);
Letter,

/// <summary>
/// Legal: 8.5 inches by 14 inches.
/// </summary>
public static PaperFormat Legal => new PaperFormat(8.5m, 14);
Legal,

/// <summary>
/// Tabloid: 11 inches by 17 inches.
/// </summary>
public static PaperFormat Tabloid => new PaperFormat(11, 17);
Tabloid,

/// <summary>
/// Ledger: 17 inches by 11 inches.
/// </summary>
public static PaperFormat Ledger => new PaperFormat(17, 11);
Ledger,

/// <summary>
/// A0: 33.1 inches by 46.8 inches.
/// </summary>
public static PaperFormat A0 => new PaperFormat(33.1m, 46.8m);
A0,

/// <summary>
/// A1: 23.4 inches by 33.1 inches.
/// </summary>
public static PaperFormat A1 => new PaperFormat(23.4m, 33.1m);
A1,

/// <summary>
/// A2: 16.5 inches by 23.4 inches.
/// </summary>
public static PaperFormat A2 => new PaperFormat(16.54m, 23.4m);
A2,

/// <summary>
/// A3: 11.7 inches by 16.5 inches.
/// </summary>
public static PaperFormat A3 => new PaperFormat(11.7m, 16.54m);
A3,

/// <summary>
/// A4: 8.27 inches by 11.7 inches.
/// </summary>
public static PaperFormat A4 => new PaperFormat(8.27m, 11.7m);
A4,

/// <summary>
/// A5: 5.83 inches by 8.27 inches.
/// </summary>
public static PaperFormat A5 => new PaperFormat(5.83m, 8.27m);
A5,

/// <summary>
/// A6: 4.13 inches by 5.83 inches.
/// </summary>
public static PaperFormat A6 => new PaperFormat(4.13m, 5.83m);

/// <summary>
/// Page width in inches.
/// </summary>
public decimal Width { get; set; }

/// <summary>
/// Page height in inches.
/// </summary>
public decimal Height { get; set; }

/// <inheritdoc cref="IEquatable{T}"/>
public static bool operator ==(PaperFormat left, PaperFormat right)
=> EqualityComparer<PaperFormat>.Default.Equals(left, right);

/// <inheritdoc cref="IEquatable{T}"/>
public static bool operator !=(PaperFormat left, PaperFormat right) => !(left == right);

/// <summary>
/// Checks for object equality.
/// </summary>
/// <param name="obj">Format to check.</param>
/// <returns>Whether the objects are equal or not.</returns>
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}

return Equals((PaperFormat)obj);
}

/// <summary>
/// Checks for object equality.
/// </summary>
/// <param name="other">Format to check.</param>
/// <returns>Whether the objects are equal or not.</returns>
public bool Equals(PaperFormat other)
=> other != null &&
Width == other.Width &&
Height == other.Height;

/// <inheritdoc cref="object.GetHashCode"/>
public override int GetHashCode()
=> 859600377
^ Width.GetHashCode()
^ Height.GetHashCode();
A6,
}
}
2 changes: 1 addition & 1 deletion src/PlaywrightSharp/Transport/Channels/PageChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ internal async Task<string> GetPdfAsync(
bool printBackground,
bool landscape,
string pageRanges,
PaperFormat format,
PaperFormat? format,
string width,
string height,
Margin margin,
Expand Down

0 comments on commit 708a02f

Please sign in to comment.