How to use Equals method of PuppeteerSharp.PdfOptions class

Best Puppeteer-sharp code snippet using PuppeteerSharp.PdfOptions.Equals

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

PdfOptions.cs

Source: PdfOptions.cs Github

copy
1using System;
2using System.Collections.Generic;
3using PuppeteerSharp.Media;
4
5namespace PuppeteerSharp
6{
7    /// <summary>
8    /// Options to be used in <see cref="Page.PdfAsync(string, PdfOptions)"/>, <see cref="Page.PdfStreamAsync(PdfOptions)"/> and <see cref="Page.PdfDataAsync(PdfOptions)"/>
9    /// </summary>
10    public class PdfOptions : IEquatable<PdfOptions>
11    {
12        /// <summary>
13        /// Initializes a new instance of the <see cref="PuppeteerSharp.PdfOptions"/> class.
14        /// </summary>
15        public PdfOptions()
16        {
17        }
18
19        /// <summary>
20        /// Scale of the webpage rendering. Defaults to <c>1</c>. Scale amount must be between 0.1 and 2.
21        /// </summary>
22        public decimal Scale { get; set; } = 1;
23
24        /// <summary>
25        /// Display header and footer. Defaults to <c>false</c>
26        /// </summary>
27        public bool DisplayHeaderFooter { get; set; }
28
29        /// <summary>
30        /// HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
31        ///   <c>date</c> - formatted print date
32        ///   <c>title</c> - document title
33        ///   <c>url</c> - document location
34        ///   <c>pageNumber</c> - current page number
35        ///   <c>totalPages</c> - total pages in the document
36        /// </summary>
37        public string HeaderTemplate { get; set; } = string.Empty;
38
39        /// <summary>
40        /// HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them:
41        ///   <c>date</c> - formatted print date
42        ///   <c>title</c> - document title
43        ///   <c>url</c> - document location
44        ///   <c>pageNumber</c> - current page number
45        ///   <c>totalPages</c> - total pages in the document
46        /// </summary>
47        public string FooterTemplate { get; set; } = string.Empty;
48
49        /// <summary>
50        /// Print background graphics. Defaults to <c>false</c>
51        /// </summary>
52        public bool PrintBackground { get; set; }
53
54        /// <summary>
55        /// Paper orientation.. Defaults to <c>false</c>
56        /// </summary>
57        public bool Landscape { get; set; }
58
59        /// <summary>
60        /// Paper ranges to print, e.g., <c>1-5, 8, 11-13</c>. Defaults to the empty string, which means print all pages
61        /// </summary>
62        public string PageRanges { get; set; } = string.Empty;
63
64        /// <summary>
65        /// Paper format. If set, takes priority over <see cref="Width"/> and <see cref="Height"/>
66        /// </summary>
67        public PaperFormat Format { get; set; }
68
69        /// <summary>
70        /// Paper width, accepts values labeled with units
71        /// </summary>
72        public object Width { get; set; }
73
74        /// <summary>
75        /// Paper height, accepts values labeled with units
76        /// </summary>
77        public object Height { get; set; }
78
79        /// <summary>
80        /// Paper margins, defaults to none
81        /// </summary>
82        public MarginOptions MarginOptions { get; set; } = new MarginOptions();
83
84        /// <summary>
85        /// Give any CSS <c>@page</c> size declared in the page priority over what is declared in <c>width</c> and <c>height</c> or <c>format</c> options. 
86        /// Defaults to <c>false</c>, which will scale the content to fit the paper size.
87        /// </summary>
88        public bool PreferCSSPageSize { get; set; }
89
90        /// <inheritdoc/>
91        public override bool Equals(object obj)
92        {
93            if (obj == null || GetType() != obj.GetType())
94            {
95                return false;
96            }
97
98            return Equals((PdfOptions)obj);
99        }
100
101        /// <inheritdoc/>
102        public bool Equals(PdfOptions options)
103            => options != null &&
104                   Scale == options.Scale &&
105                   DisplayHeaderFooter == options.DisplayHeaderFooter &&
106                   HeaderTemplate == options.HeaderTemplate &&
107                   FooterTemplate == options.FooterTemplate &&
108                   PrintBackground == options.PrintBackground &&
109                   Landscape == options.Landscape &&
110                   PageRanges == options.PageRanges &&
111                   EqualityComparer<PaperFormat>.Default.Equals(Format, options.Format) &&
112                   EqualityComparer<object>.Default.Equals(Width, options.Width) &&
113                   EqualityComparer<object>.Default.Equals(Height, options.Height) &&
114                   EqualityComparer<MarginOptions>.Default.Equals(MarginOptions, options.MarginOptions) &&
115                   PreferCSSPageSize == options.PreferCSSPageSize;
116
117        /// <inheritdoc/>
118        public override int GetHashCode()
119            => -711844102
120                ^ Scale.GetHashCode()
121                ^ DisplayHeaderFooter.GetHashCode()
122                ^ EqualityComparer<string>.Default.GetHashCode(HeaderTemplate)
123                ^ EqualityComparer<string>.Default.GetHashCode(FooterTemplate)
124                ^ PrintBackground.GetHashCode()
125                ^ Landscape.GetHashCode()
126                ^ EqualityComparer<string>.Default.GetHashCode(PageRanges)
127                ^ EqualityComparer<PaperFormat>.Default.GetHashCode(Format)
128                ^ EqualityComparer<object>.Default.GetHashCode(Width)
129                ^ EqualityComparer<object>.Default.GetHashCode(Height)
130                ^ EqualityComparer<MarginOptions>.Default.GetHashCode(MarginOptions)
131                ^ PreferCSSPageSize.GetHashCode();
132
133        /// <inheritdoc/>
134        public static bool operator ==(PdfOptions left, PdfOptions right)
135            => EqualityComparer<PdfOptions>.Default.Equals(left, right);
136
137        /// <inheritdoc/>
138        public static bool operator !=(PdfOptions left, PdfOptions right) => !(left == right);
139    }
140}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in PdfOptions

Trigger Equals code on LambdaTest Cloud Grid

Execute automation tests with Equals on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)