How to use PaperFormat method of PuppeteerSharp.Media.PaperFormat class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Media.PaperFormat.PaperFormat

Default.aspx.cs

Source:Default.aspx.cs Github

copy

Full Screen

...31 var margin = new MarginOptions();32 margin.Top = "10";33 var pdfOptions = new PdfOptions34 {35 Format = PaperFormat.A2,36 Landscape = true,37 PrintBackground = true,38 DisplayHeaderFooter = true,39 MarginOptions = margin40 };41 var page = await browser.NewPageAsync().ConfigureAwait(false);42 await page.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/table.html").ConfigureAwait(false);43 await page.WaitForTimeoutAsync(2000);44 await page.PdfAsync(output, pdfOptions).ConfigureAwait(false);45 var fileName2 = Server.MapPath("~/PDF/table-datatable.pdf");46 var output2 = "" + fileName2;47 var browser2 = await Puppeteer.LaunchAsync(new LaunchOptions48 {49 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",50 DefaultViewport = vp51 }).ConfigureAwait(false);52 53 var pdfOptions2 = new PdfOptions54 {55 Format = PaperFormat.A2,56 Landscape = true,57 PrintBackground = true,58 DisplayHeaderFooter = true,59 MarginOptions = margin60 };61 var page2 = await browser.NewPageAsync().ConfigureAwait(false);62 await page2.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/table-datatable.html").ConfigureAwait(false);63 await page2.WaitForTimeoutAsync(2000);64 await page2.PdfAsync(output2, pdfOptions).ConfigureAwait(false);65 var fileName3 = Server.MapPath("~/PDF/ui-chart-apexcharts.pdf");66 var output3 = "" + fileName3;67 var browser3 = await Puppeteer.LaunchAsync(new LaunchOptions68 {69 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",70 DefaultViewport = vp71 }).ConfigureAwait(false);72 var pdfOptions3 = new PdfOptions73 {74 Format = PaperFormat.A2,75 Landscape = true,76 PrintBackground = true,77 DisplayHeaderFooter=true,78 MarginOptions=margin79 };80 var page3 = await browser.NewPageAsync().ConfigureAwait(false);81 await page3.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/ui-chart-apexcharts.html").ConfigureAwait(false);82 //await page3.WaitForFunctionAsync("windows.innerWidth<1600");83 await page3.WaitForTimeoutAsync(2000);84 await page3.PdfAsync(output3, pdfOptions).ConfigureAwait(false);85 var fileName4 = Server.MapPath("~/PDF/component-card.pdf");86 var output4 = "" + fileName4;87 var browser4 = await Puppeteer.LaunchAsync(new LaunchOptions88 {89 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",90 DefaultViewport = vp91 }).ConfigureAwait(false);92 var pdfOptions4 = new PdfOptions93 {94 Format = PaperFormat.A2,95 Landscape = true,96 PrintBackground = true,97 DisplayHeaderFooter = true,98 MarginOptions = margin99 };100 var page4 = await browser.NewPageAsync().ConfigureAwait(false);101 await page4.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/component-card.html").ConfigureAwait(false);102 await page4.WaitForTimeoutAsync(2000);103 await page4.PdfAsync(output4, pdfOptions).ConfigureAwait(false);104 var fileName5 = Server.MapPath("~/PDF/component-pagination.pdf");105 var output5 = "" + fileName5;106 var browser5 = await Puppeteer.LaunchAsync(new LaunchOptions107 {108 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",109 DefaultViewport = vp110 }).ConfigureAwait(false);111 var pdfOptions5 = new PdfOptions112 {113 Format = PaperFormat.A2,114 Landscape = true,115 PrintBackground = true,116 DisplayHeaderFooter = true,117 MarginOptions = margin118 };119 var page5 = await browser.NewPageAsync().ConfigureAwait(false);120 await page5.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/component-pagination.html").ConfigureAwait(false);121 await page5.WaitForTimeoutAsync(2000);122 await page5.PdfAsync(output5, pdfOptions).ConfigureAwait(false);123 var fileName6 = Server.MapPath("~/PDF/component-progress.pdf");124 var output6 = "" + fileName6;125 var browser6 = await Puppeteer.LaunchAsync(new LaunchOptions126 {127 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",128 DefaultViewport = vp129 }).ConfigureAwait(false);130 var pdfOptions6 = new PdfOptions131 {132 Format = PaperFormat.A2,133 Landscape = true,134 PrintBackground = true,135 DisplayHeaderFooter = true,136 MarginOptions = margin137 };138 var page6 = await browser.NewPageAsync().ConfigureAwait(false);139 await page6.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/component-progress.html").ConfigureAwait(false);140 await page6.WaitForTimeoutAsync(2000);141 await page6.PdfAsync(output6, pdfOptions).ConfigureAwait(false);142 var fileName7 = Server.MapPath("~/PDF/form-element-checkbox.pdf");143 var output7 = "" + fileName7;144 var browser7 = await Puppeteer.LaunchAsync(new LaunchOptions145 {146 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",147 DefaultViewport = vp148 }).ConfigureAwait(false);149 var pdfOptions7 = new PdfOptions150 {151 Format = PaperFormat.A2,152 Landscape = true,153 PrintBackground = true,154 DisplayHeaderFooter = true,155 MarginOptions = margin156 };157 var page7 = await browser.NewPageAsync().ConfigureAwait(false);158 await page7.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/form-element-checkbox.html").ConfigureAwait(false);159 await page7.WaitForTimeoutAsync(2000);160 await page7.PdfAsync(output7, pdfOptions).ConfigureAwait(false);161 var fileName8 = Server.MapPath("~/PDF/ui-widgets-pricing.pdf");162 var output8 = "" + fileName8;163 var browser8 = await Puppeteer.LaunchAsync(new LaunchOptions164 {165 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",166 DefaultViewport = vp167 }).ConfigureAwait(false);168 var pdfOptions8 = new PdfOptions169 {170 Format = PaperFormat.A2,171 Landscape = true,172 PrintBackground = true,173 DisplayHeaderFooter = true,174 MarginOptions = margin175 };176 var page8 = await browser.NewPageAsync().ConfigureAwait(false);177 await page8.GoToAsync("C:/Users/sonam/source/repos/WebApplication6/mazer-main/dist/ui-widgets-pricing.html").ConfigureAwait(false);178 await page8.WaitForTimeoutAsync(2000);179 await page8.PdfAsync(output8, pdfOptions).ConfigureAwait(false);180 var pdfs = new List<PdfDocument>();181 pdfs.Add(PdfDocument.FromFile("C:/Users/sonam/source/repos/WebApplication6/WebApplication6/PDF/table.pdf"));182 pdfs.Add(PdfDocument.FromFile("C:/Users/sonam/source/repos/WebApplication6/WebApplication6/PDF/table-datatable.pdf"));183 pdfs.Add(PdfDocument.FromFile("C:/Users/sonam/source/repos/WebApplication6/WebApplication6/PDF/ui-chart-apexcharts.pdf"));184 pdfs.Add(PdfDocument.FromFile("C:/Users/sonam/source/repos/WebApplication6/WebApplication6/PDF/component-card.pdf"));...

Full Screen

Full Screen

CreatePdf.cs

Source:CreatePdf.cs Github

copy

Full Screen

...44 pdfOptions.FooterTemplate = parameters.FooterTemplate;45 pdfOptions.PrintBackground = parameters.PrintBackground;46 pdfOptions.Landscape = parameters.Landscape;47 pdfOptions.PageRanges = parameters.PageRanges;48 pdfOptions.Format = ConvertToPaperFormat(parameters.PaperFormat);49 pdfOptions.MarginOptions = new MarginOptions50 {51 Top = parameters.TopMargin,52 Left = parameters.LeftMargin,53 Bottom = parameters.BottomMargin,54 Right = parameters.RightMargin55 };56 pdfOptions.PreferCSSPageSize = parameters.PreferCSSPageSize;57 pdf = await page.PdfStreamAsync(pdfOptions);58 Console.WriteLine($"{guid} {DateTime.Now}: PDF generated");59 60 var closePageTask = page.CloseAsync();61 await closePageTask;62 Console.WriteLine($"{guid} {DateTime.Now}: page closed");63 }64 var closeBrowserTask = browser.CloseAsync();65 await closeBrowserTask;66 Console.WriteLine($"{guid} {DateTime.Now}: browser closed");67 68 return pdf;69 }70 }71 private static PaperFormat ConvertToPaperFormat(string paperFormat)72 {73 switch (paperFormat)74 {75 case null:76 return null;77 case "Letter":78 return PaperFormat.Letter;79 case "Legal":80 return PaperFormat.Legal;81 case "Tabloid":82 return PaperFormat.Tabloid;83 case "Ledger":84 return PaperFormat.Ledger;85 case "A0":86 return PaperFormat.A0;87 case "A1":88 return PaperFormat.A1;89 case "A2":90 return PaperFormat.A2;91 case "A3":92 return PaperFormat.A3;93 case "A4":94 return PaperFormat.A4;95 case "A5":96 return PaperFormat.A5;97 case "A6":98 return PaperFormat.A6;99 default:100 return null;101 }102 }103 }104}...

Full Screen

Full Screen

DocumentsV2Controller.cs

Source:DocumentsV2Controller.cs Github

copy

Full Screen

...40 using (StreamReader stringReader = new StreamReader(x.OpenReadStream()))41 using (var page = await s_browser.NewPageAsync()) {42 await page.SetContentAsync(await stringReader.ReadToEndAsync());43 var fileName = $"{Guid.NewGuid()}.pdf";44 await page.PdfAsync($"{Directory.GetCurrentDirectory()}/files/{fileName}", new PdfOptions() { Format = PuppeteerSharp.Media.PaperFormat.A4, Landscape = landscape, OmitBackground = true, PrintBackground = true });45 return fileName;46 }47 });48 var files = await Task.WhenAll(tasks);49 return files.ToList();50 }51 [NonAction]52 public async Task<List<string>> GeneratePdfAsync(List<string> url, bool landscape) {53 s_browser ??= await Puppeteer.LaunchAsync(_browserOptions);54 var tasks = url.Select(async x => {55 using (var page = await s_browser.NewPageAsync()) {56 await page.GoToAsync(x);57 var fileName = $"{Guid.NewGuid()}.pdf";58 await page.PdfAsync($"{Directory.GetCurrentDirectory()}/files/{fileName}", new PdfOptions() { Format = PuppeteerSharp.Media.PaperFormat.A4, Landscape = landscape, OmitBackground = true, PrintBackground = true });59 return fileName;60 }61 });62 var files = await Task.WhenAll(tasks);63 return files.ToList();64 }65 }66}...

Full Screen

Full Screen

HtmlToPdfConverter.cs

Source:HtmlToPdfConverter.cs Github

copy

Full Screen

...37 process.Start();38 string result = process.StandardOutput.ReadToEnd();39 process.WaitForExit();40 }41 public async Task<byte[]> ConvertToPdf(string resPath, string html, PaperFormat paperFormat, int margin = 32, decimal scale = 1)42 {43 using (var page = await browser.NewPageAsync())44 {45 if(resPath != null)46 await page.GoToAsync(resPath);47 await page.SetContentAsync(html);48 string marginStr = margin + "px";49 var pdfOptions = new PdfOptions50 {51 Format = paperFormat,52 MarginOptions = new MarginOptions53 {54 Left = marginStr,55 Right = marginStr,...

Full Screen

Full Screen

PdfOptionsConverter.cs

Source:PdfOptionsConverter.cs Github

copy

Full Screen

...27 },28 PreferCSSPageSize = pdfOptions.PreferCSSPageSize29 };30 }31 private PaperFormat ConvertFormat(Format format)32 {33 switch (format.Type)34 {35 case FormatType.A0:36 return PaperFormat.A0;37 case FormatType.A1:38 return PaperFormat.A1;39 case FormatType.A2:40 return PaperFormat.A2;41 case FormatType.A3:42 return PaperFormat.A3;43 case FormatType.A4:44 return PaperFormat.A4;45 case FormatType.A5:46 return PaperFormat.A5;47 case FormatType.A6:48 return PaperFormat.A6;49 case FormatType.Letter:50 return PaperFormat.Letter;51 case FormatType.Legal:52 return PaperFormat.Legal;53 case FormatType.Ledger:54 return PaperFormat.Ledger;55 case FormatType.Tabloid:56 return PaperFormat.Tabloid;57 default:58 return new PaperFormat(format.Width, format.Height);59 }60 }61 }62}...

Full Screen

Full Screen

PaperFormat.cs

Source:PaperFormat.cs Github

copy

Full Screen

...3 /// <summary>4 /// Paper format.5 /// </summary>6 /// <seealso cref="PdfOptions.Format"/>7 public class PaperFormat8 {9 internal decimal Width { get; set; }10 internal decimal Height { get; set; }11 private PaperFormat(decimal width, decimal height)12 {13 Width = width;14 Height = height;15 }16 /// <summary>17 /// Letter.18 /// </summary>19 public static readonly PaperFormat Letter = new PaperFormat(8.5m, 11);20 /// <summary>21 /// Legal.22 /// </summary>23 public static readonly PaperFormat Legal = new PaperFormat(8.5m, 14);24 /// <summary>25 /// Tabloid.26 /// </summary>27 public static readonly PaperFormat Tabloid = new PaperFormat(11, 17);28 /// <summary>29 /// Ledger.30 /// </summary>31 public static readonly PaperFormat Ledger = new PaperFormat(17, 11);32 /// <summary>33 /// A0.34 /// </summary>35 public static readonly PaperFormat A0 = new PaperFormat(33.1m, 46.8m);36 /// <summary>37 /// A1.38 /// </summary>39 public static readonly PaperFormat A1 = new PaperFormat(23.4m, 33.1m);40 /// <summary>41 /// A2.42 /// </summary>43 public static readonly PaperFormat A2 = new PaperFormat(16.5m, 23.4m);44 /// <summary>45 /// A3.46 /// </summary>47 public static readonly PaperFormat A3 = new PaperFormat(11.7m, 16.5m);48 /// <summary>49 /// A4.50 /// </summary>51 public static readonly PaperFormat A4 = new PaperFormat(8.27m, 11.7m);52 /// <summary>53 /// A5.54 /// </summary>55 public static readonly PaperFormat A5 = new PaperFormat(5.83m, 8.27m);56 /// <summary>57 /// A6.58 /// </summary>59 public static readonly PaperFormat A6 = new PaperFormat(4.13m, 5.83m);60 }61}...

Full Screen

Full Screen

DocumentsController.cs

Source:DocumentsController.cs Github

copy

Full Screen

...19 var options = new LaunchOptions { Headless = true, ExecutablePath = @"/usr/bin/chromium-browser", Args = new string[] { "--no-sandbox" } };20 using (var browser = await Puppeteer.LaunchAsync(options))21 using (var page = await browser.NewPageAsync()) {22 await page.GoToAsync(url);23 return await page.PdfStreamAsync(new PdfOptions() { Format = PuppeteerSharp.Media.PaperFormat.A4, Landscape = landscape, OmitBackground = true, PrintBackground = true });24 }25 }26 }27}...

Full Screen

Full Screen

PdfHelper.cs

Source:PdfHelper.cs Github

copy

Full Screen

...12 foreach (var c in Path.GetInvalidFileNameChars())13 pageTitle = pageTitle.Replace(c, '_');14 return $"{pageTitle}.pdf";15 }16 public static PaperFormat ParsePaperFormat(string format)17 {18 return format switch19 {20 "A0" => PaperFormat.A0,21 "A1" => PaperFormat.A1,22 "A2" => PaperFormat.A2,23 "A3" => PaperFormat.A3,24 "A4" => PaperFormat.A4,25 "A5" => PaperFormat.A5,26 "A6" => PaperFormat.A6,27 _ => PaperFormat.A4,28 };29 }30 }31}...

Full Screen

Full Screen

PaperFormat

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp;2using System;3using System.Threading.Tasks;4{5 {6 static void Main(string[] args)7 {8 MainAsync().Wait();9 }10 static async Task MainAsync()11 {12 var options = new LaunchOptions { Headless = true };13 using (var browser = await Puppeteer.LaunchAsync(options))14 using (var page = await browser.NewPageAsync())15 {16 await page.PdfAsync("google.pdf", new PdfOptions { Format = PaperFormat.A4 });17 }18 }19 }20}21using PuppeteerSharp;22using System;23using System.Threading.Tasks;24{25 {26 static void Main(string[] args)27 {28 MainAsync().Wait();29 }30 static async Task MainAsync()31 {32 var options = new LaunchOptions { Headless = true };33 using (var browser = await Puppeteer.LaunchAsync(options))34 using (var page = await browser.NewPageAsync())35 {36 await page.PdfAsync("google.pdf", new PdfOptions { Format = PaperFormat.Legal });37 }38 }39 }40}41using PuppeteerSharp;42using System;43using System.Threading.Tasks;44{45 {46 static void Main(string[] args)47 {48 MainAsync().Wait();49 }50 static async Task MainAsync()51 {52 var options = new LaunchOptions { Headless = true };53 using (var browser = await Puppeteer.LaunchAsync(options))54 using (var page = await browser.NewPageAsync())55 {56 await page.PdfAsync("google.pdf", new PdfOptions { Format = PaperFormat.Letter });57 }58 }59 }60}61using PuppeteerSharp;62using System;63using System.Threading.Tasks;64{

Full Screen

Full Screen

PaperFormat

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Threading.Tasks;4using PuppeteerSharp;5{6 {7 static async Task Main(string[] args)8 {9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions10 {11 Args = new string[] { "--no-sandbox", "--disable-setuid-sandbox" }12 });13 var page = await browser.NewPageAsync();

Full Screen

Full Screen

PaperFormat

Using AI Code Generation

copy

Full Screen

1var paperFormat = new PaperFormat(8.5, 11, PaperFormatUnit.Inches);2await page.PdfAsync("2.pdf", new PdfOptions3{4});5var paperFormat = new PaperFormat(210, 297, PaperFormatUnit.Millimeters);6await page.PdfAsync("3.pdf", new PdfOptions7{8});9var paperFormat = new PaperFormat(595, 842, PaperFormatUnit.Points);10await page.PdfAsync("4.pdf", new PdfOptions11{12});13var paperFormat = new PaperFormat(612, 792, PaperFormatUnit.Pixels);14await page.PdfAsync("5.pdf", new PdfOptions15{16});17var paperFormat = new PaperFormat(8.5, 11, PaperFormatUnit.Inches);18await page.PdfAsync("6.pdf", new PdfOptions19{20});21var paperFormat = new PaperFormat(8.5, 11, PaperFormatUnit.Inches);22await page.PdfAsync("7.pdf", new PdfOptions23{24});25var paperFormat = new PaperFormat(8.5, 11, PaperFormatUnit.Inches);26await page.PdfAsync("8.pdf", new PdfOptions27{28});29var paperFormat = new PaperFormat(8.5, 11, PaperFormatUnit.Inches);30await page.PdfAsync("9.pdf", new PdfOptions31{32});33var paperFormat = new PaperFormat(8.5,

Full Screen

Full Screen

PaperFormat

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync().GetAwaiter().GetResult();9 }10 static async Task MainAsync()11 {12 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);13 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))14 using (var page = await browser.NewPageAsync())15 {16 await page.SetContentAsync(@"17 <div style='width: 8in; height: 4in; background-color: green'>18 </div>");19 await page.PdfAsync("output.pdf", new PdfOptions20 {21 {22 }23 });24 }25 }26 }27}28using System;29using System.Threading.Tasks;30using PuppeteerSharp;31{32 {33 static void Main(string[] args)34 {35 MainAsync().GetAwaiter().GetResult();36 }37 static async Task MainAsync()38 {39 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);40 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))41 using (var page = await browser.NewPageAsync())42 {43 await page.SetContentAsync(@"44 <div style='width: 8in; height: 4in; background-color: green'>45 </div>");46 await page.PdfAsync("output.pdf", new PdfOptions47 {48 {

Full Screen

Full Screen

PaperFormat

Using AI Code Generation

copy

Full Screen

1var paperFormat = new PaperFormat(8.27, 11.69, PaperFormatUnit.Inches);2await page.SetContentAsync("<h1>Page Header</h1><p>Page Content</p>");3await page.PdfAsync("page.pdf", new PdfOptions { Format = paperFormat });4var paperFormat = new PaperFormat(8.27, 11.69, PaperFormatUnit.Inches);5await page.SetContentAsync("<h1>Page Header</h1><p>Page Content</p>");6await page.PdfAsync("page.pdf", new PdfOptions { Format = paperFormat });7var paperFormat = new PaperFormat(8.27, 11.69, PaperFormatUnit.Inches);8await page.SetContentAsync("<h1>Page Header</h1><p>Page Content</p>");9await page.PdfAsync("page.pdf", new PdfOptions { Format = paperFormat });10var paperFormat = new PaperFormat(8.27, 11.69, PaperFormatUnit.Inches);11await page.SetContentAsync("<h1>Page Header</h1><p>Page Content</p>");12await page.PdfAsync("page.pdf", new PdfOptions { Format = paperFormat });13var paperFormat = new PaperFormat(8.27, 11.69, PaperFormatUnit.Inches);14await page.SetContentAsync("<h1>Page Header</h1><p>Page Content</p>");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

Most used method in PaperFormat

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful