How to use PdfAsync method of PuppeteerSharp.Page class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Page.PdfAsync

PDFDocument.cs

Source:PDFDocument.cs Github

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Drawing;4using System.IO;5using System.Threading;6using System.Threading.Tasks;7using PuppeteerSharp;8using Nito.AsyncEx;9using Nito.AsyncEx.Synchronous;10namespace BarnardTech.PDF2IMG11{12 public class PDFDocument : IDisposable13 {14 public event PDFLoadedDelegate OnPDFLoaded;15 Browser chromeBrowser;16 Page chromePage;17 List<PDFPage> pdfPages = new List<PDFPage>();18 private bool readyFired = false;19 private Action _onReady;20 AutoResetEvent pdfLoadEvent = new AutoResetEvent(false);21 private bool _pdfLoadWaiting = false;22 public int PageCount = 0;23 public int CurrentPageNumber = 0;24 private List<InternalTextContent> textContents = new List<InternalTextContent>();25 FileResourceHandlerFactory fileResourceHandlerFactory;26 private static readonly object _initializeLock = new object();27 /// <summary>28 /// Create a new PageRenderer. This function uses PuppeteerSharp to control an in-background copy of Chrome.29 /// If Chrome isn't available in the current application's path, it'll automatically download one. This means30 /// that when creating a PageRenderer for the first time, there may be a significant wait while Chrome is31 /// downloaded.32 /// </summary>33 public PDFDocument(string browserPath = "")34 {35 // lock workaround required due to potential issues with multiple threads launching at the same time:36 // https://github.com/garris/BackstopJS/issues/108437 lock (_initializeLock)38 {39 AutoResetEvent readyEvent = new AutoResetEvent(false);40 new Task(async () =>41 {42 if (string.IsNullOrEmpty(browserPath))43 {44 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);45 }46 else47 {48 await new BrowserFetcher(new BrowserFetcherOptions() { Path = browserPath }).DownloadAsync(BrowserFetcher.DefaultRevision);49 }50 var browser = await Puppeteer.LaunchAsync(new LaunchOptions51 {52 Headless = true53 });54 //Browser browser = null;55 //lock (_initializeLock)56 //{57 // var task = Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });58 // task.WaitAndUnwrapException();59 // browser = task.Result;60 //}61 var page = await browser.NewPageAsync();62 await page.SetRequestInterceptionAsync(true);63 _init(browser, page, () =>64 {65 readyEvent.Set();66 });67 }).Start();68 readyEvent.WaitOne();69 }70 }71 private PDFDocument(Browser browser, Page page, Action onReady)72 {73 _init(browser, page, onReady);74 }75 private void _init(Browser browser, Page page, Action onReady)76 {77 _onReady = onReady;78 chromeBrowser = browser;79 chromePage = page;80 fileResourceHandlerFactory = new FileResourceHandlerFactory("pdfviewer", "host", Directory.GetCurrentDirectory());81 page.Request += Page_Request;82 page.RequestFinished += Page_RequestFinished;83 page.Load += Page_Load;84 page.GoToAsync("http://host/web/pdfedit.html");85 }86 private void Page_Load(object sender, EventArgs e)87 {88 Console.WriteLine("PDF.JS Loaded.");89 if (!readyFired)90 {91 readyFired = true;92 if (_onReady != null)93 {94 _onReady();95 }96 }97 }98 private void Page_RequestFinished(object sender, RequestEventArgs e)99 {100 }101 private void Page_Request(object sender, RequestEventArgs e)102 {103 string extension;104 string content = fileResourceHandlerFactory.get_content(new Uri(e.Request.Url), out extension);105 ResponseData response = new ResponseData();106 response.Status = System.Net.HttpStatusCode.OK;107 response.Body = content;108 e.Request.RespondAsync(response);109 }110 /// <summary>111 /// Loads a PDF from disk given the requested filename.112 /// </summary>113 /// <param name="filename">The filename of the PDF.</param>114 public void LoadPDF(string filename)115 {116 pdfPages = new List<PDFPage>();117 //pdfLoadEvent.Reset();118 var task = LoadPDFAsync(filename);119 task.WaitAndUnwrapException();120 //LoadPDFAsync(filename);121 //pdfLoadEvent.WaitOne();122 }123 /// <summary>124 /// Loads a PDF from a byte array.125 /// </summary>126 /// <param name="buffer">The byte array containing the PDF data.</param>127 public void LoadPDF(byte[] buffer)128 {129 //pdfLoadEvent.Reset();130 var task = LoadPDFAsync(buffer);131 task.WaitAndUnwrapException();132 //pdfLoadEvent.WaitOne();133 }134 /// <summary>135 /// Loads a PDF from a stream. Reading begins from wherever the stream's position is currently set - it will not be reset to 0.136 /// </summary>137 /// <param name="stream">The stream containing the PDF data.</param>138 public void LoadPDF(Stream stream)139 {140 //pdfLoadEvent.Reset();141 var task = LoadPDFAsync(stream);142 task.WaitAndUnwrapException();143 //pdfLoadEvent.WaitOne();144 }145 /// <summary>146 /// Loads a PDF from disk given the requested filename.147 /// </summary>148 /// <param name="filename">The filename of the PDF.</param>149 public async Task<bool> LoadPDFAsync(string filename)150 {151 FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);152 byte[] buffer = new byte[fStream.Length];153 byte[] chunk = new byte[4096];154 while (fStream.Position < fStream.Length)155 {156 long offset = fStream.Position;157 int bytes = await fStream.ReadAsync(chunk, 0, chunk.Length);158 Array.Copy(chunk, 0, buffer, offset, bytes);159 }160 return await LoadPDFAsync(buffer);161 }162 /// <summary>163 /// Loads a PDF from a stream. Reading begins from wherever the stream's position is currently set - it will not be reset to 0.164 /// </summary>165 /// <param name="stream">The stream containing the PDF data.</param>166 public async Task<bool> LoadPDFAsync(Stream stream)167 {168 byte[] buffer = new byte[stream.Length - stream.Position];169 byte[] chunk = new byte[4096];170 while (stream.Position < stream.Length)171 {172 long offset = stream.Position;173 int bytes = await stream.ReadAsync(chunk, 0, chunk.Length);174 Array.Copy(chunk, 0, buffer, offset, bytes);175 }176 return await LoadPDFAsync(buffer);177 }178 /// <summary>179 /// Loads a PDF from a byte array.180 /// </summary>181 /// <param name="buffer">The byte array containing the PDF data.</param>182 public async Task<bool> LoadPDFAsync(byte[] buffer)183 {184 if (!_pdfLoadWaiting)185 {186 _pdfLoadWaiting = true;187 var asBase64 = Convert.ToBase64String(buffer);188 try189 {190 PageCount = await chromePage.EvaluateFunctionAsync<int>("loadPDF", new[] { asBase64 });191 }192 catch (Exception ex)193 {194 throw new Exception("Cannot load PDF", ex);195 }196 Console.WriteLine("PDF Loaded.");197 for (int i = 0; i < PageCount; i++)198 {199 string rectJson = await chromePage.EvaluateFunctionAsync<string>("getMediaBox", new[] { i });200 RectangleF mediaBox = Newtonsoft.Json.JsonConvert.DeserializeObject<RectangleF>(rectJson);201 PDFPage p = new PDFPage(i, mediaBox, chromePage);202 pdfPages.Add(p);203 int rotation = await chromePage.EvaluateFunctionAsync<int>("getRotation", new[] { i });204 p.Rotate = rotation;205 }206 _pdfLoadWaiting = false;207 pdfLoadEvent.Set();208 if (OnPDFLoaded != null)209 {210 new Task(() =>211 {212 OnPDFLoaded(this, new EventArgs());213 }).Start();214 }215 return true;216 }217 else218 {219 throw new Exception("A PDF file is already waiting to be loaded.");220 }221 }222 public bool InsertImage(string imageName, Bitmap image, int pageNumber, RectangleF drawRect)223 {224 return InsertImage(imageName, image, pageNumber, drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height);225 }226 public bool InsertImage(string imageName, Bitmap image, int pageNumber, float X, float Y, float Width, float Height)227 {228 Task<bool> t = InsertImageAsync(imageName, image, pageNumber, X, Y, Width, Height);229 t.Wait();230 return t.Result;231 }232 public async Task<bool> InsertImageAsync(string imageName, Bitmap image, int pageNumber, RectangleF drawRect)233 {234 return await InsertImageAsync(imageName, image, pageNumber, drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height);235 }236 public async Task<bool> InsertImageAsync(string imageName, Bitmap image, int pageNumber, float X, float Y, float Width, float Height)237 {238 float outX;239 float outY;240 float outWidth;241 float outHeight;242 if (pdfPages[pageNumber].Rotate == 90 || pdfPages[pageNumber].Rotate == 270)243 {244 outWidth = Width;245 outHeight = Height;246 outX = Y + Height;247 outY = X;248 }249 else250 {251 outWidth = Width;252 outHeight = Height;253 outX = X;254 outY = pdfPages[pageNumber].MediaBox.Height - Y - Height;255 }256 Console.WriteLine("Page rotation: " + pdfPages[pageNumber].Rotate);257 // reverse Y coordinate258 //Y = pdfPages[pageNumber].MediaBox.Height - Y - Height;259 using (MemoryStream mStream = new MemoryStream())260 {261 image.Save(mStream, System.Drawing.Imaging.ImageFormat.Png);262 mStream.Position = 0;263 string asBase64 = Convert.ToBase64String(mStream.ToArray());264 return await chromePage.EvaluateFunctionAsync<bool>("insertPNG", new object[] { asBase64, imageName, pageNumber, outX, outY, outWidth, outHeight, pdfPages[pageNumber].Rotate });265 }266 }267 public bool SavePDF(string filename)268 {269 Task<bool> t = SavePDFAsync(filename);270 t.Wait();271 return t.Result;272 }273 public async Task<bool> SavePDFAsync(string filename)274 {275 string base64string = await chromePage.EvaluateFunctionAsync<string>("savePDF", new object[] { });276 byte[] pdfdata = Convert.FromBase64String(base64string);277 using (FileStream fStream = File.OpenWrite(filename))278 {279 using (BinaryWriter bStream = new BinaryWriter(fStream))280 {281 bStream.Write(pdfdata);282 }283 }284 return true;285 }286 public bool SavePDFToStream(Stream stream)287 {288 Task<bool> t = SavePDFToStreamAsync(stream);289 t.Wait();290 return t.Result;291 }292 public async Task<bool> SavePDFToStreamAsync(Stream stream)293 {294 string base64string = await chromePage.EvaluateFunctionAsync<string>("savePDF", new object[] { });295 byte[] pdfdata = Convert.FromBase64String(base64string);296 stream.Write(pdfdata, 0, pdfdata.Length);297 return true;298 }299 public PDFPage GetPage(int pageNumber)300 {301 return pdfPages[pageNumber];302 }303 public void Dispose()304 {305 if (chromePage != null)306 {307 chromePage.CloseAsync();308 }309 if (chromeBrowser != null)310 {311 chromeBrowser.CloseAsync();312 }313 }314 }315}...

Full Screen

Full Screen

SaveWebPage.xaml.cs

Source:SaveWebPage.xaml.cs Github

copy

Full Screen

...121 fileName = fileName.Replace(".pdf", $"{DateTime.Now.ToString("ffff")}.pdf");122 }123124 //保存PDF125 await page.PdfAsync(fileName, pdfOptions);126 EMessageBox.Show($"{fileName}保存成功");127128 //在最后记得关闭浏览器及释放资源129 browser.Disconnect();130 browser.Dispose();131 }132 catch(Exception ex)133 {134 EMessageBox.Show(ex.Message);135 }136 }137 }138}

Full Screen

Full Screen

PDFService.cs

Source:PDFService.cs Github

copy

Full Screen

...33 {34 var tempOutputPath = GetTempOutputPath();35 try36 {37 await GeneratePdfAsync(url, tempOutputPath);38 var fileContentResult = GetPDFFromDisk(tempOutputPath);39 DeleteFile(tempOutputPath);40 return fileContentResult;41 }42 catch (Exception exception)43 {44 _logger.LogError(exception, "Could not generate PDF!");45 DeleteFile(tempOutputPath);46 return null;47 }48 }49 private async Task GeneratePdfAsync(string url, string outputPath)50 {51 try52 {53 var connectOptions = new ConnectOptions54 {55 BrowserWSEndpoint = await GetWebSocketDebuggerUrl()56 };57 var browser = await Puppeteer.ConnectAsync(connectOptions);58 using (var page = await browser.NewPageAsync())59 {60 await page.GoToAsync(url, new NavigationOptions61 {62 Timeout = 0,63 WaitUntil = new[] { WaitUntilNavigation.Networkidle2 }64 });65 await page.PdfAsync(outputPath, new PdfOptions66 {67 Width = _pdfServiceConfig.PaperWidth,68 Height = _pdfServiceConfig.PaperHeight,69 MarginOptions = new MarginOptions70 {71 Top = _pdfServiceConfig.MarginTop,72 Right = _pdfServiceConfig.MarginRight,73 Bottom = _pdfServiceConfig.MarginBottom,74 Left = _pdfServiceConfig.MarginLeft75 },76 PrintBackground = true77 });78 }79 browser.Disconnect();...

Full Screen

Full Screen

Form1.cs

Source:Form1.cs Github

copy

Full Screen

...70 pdfOptions.HeaderTemplate = ""; //页眉文本71 pdfOptions.Landscape = false; //纸张方向 false-垂直 true-水平 72 pdfOptions.MarginOptions = new PuppeteerSharp.Media.MarginOptions() { Bottom = "0px", Left = "0px", Right = "0px", Top = "0px" }; //纸张边距,需要设置带单位的值,默认值是None73 pdfOptions.Scale = 1m; //PDF缩放,从0-174 await page.PdfAsync(path, pdfOptions);75 MessageBox.Show($"PDF已经保存至{path}");76 }77 private async void Form1_FormClosing(object sender, FormClosingEventArgs e)78 {79 //dispose browser80 if (browser != null)81 {82 await browser.CloseAsync();83 browser.Dispose();84 }85 }86 }87}...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

...71 }72 var outputFile = Path.Combine(Directory.GetCurrentDirectory(), $"json.pdf");73 await page.SetContentAsync(html);74 var result = await page.GetContentAsync();75 await page.PdfAsync(outputFile);76 #endregion77 //var url = "https://juejin.im";78 //await page.GoToAsync(url, WaitUntilNavigation.Networkidle0);79 //await page.ScreenshotAsync("juejin.png");80 //await page.PdfAsync("juejin.pdf");81 //var content = await page.GetContentAsync();82 //Console.WriteLine(content);83 Console.WriteLine("end");84 Console.ReadLine();85 #endregion86 }87 }88}...

Full Screen

Full Screen

DocumentsV2Controller.cs

Source:DocumentsV2Controller.cs Github

copy

Full Screen

...22 [HttpPost("byUrl")]23 public async Task<IActionResult> Get(List<string> url, bool landscape) {24 Stopwatch stopwatch = Stopwatch.StartNew();25 stopwatch.Start();26 var files = await GeneratePdfAsync(url, landscape);27 return Ok(new { Paths = files.Select(x => "/pdf/" + x), Elapsed = stopwatch.ElapsedMilliseconds });28 }29 [HttpPost("byFile")]30 public async Task<IActionResult> Post(IFormFileCollection fileStream, bool landscape) {31 Stopwatch stopwatch = Stopwatch.StartNew();32 stopwatch.Start();33 var files = await GeneratePdfAsync(fileStream.ToList(), landscape);34 return Ok(new { Paths = files.Select(x => "/pdf/" + x), Elapsed = stopwatch.ElapsedMilliseconds });35 }36 [NonAction]37 public async Task<List<string>> GeneratePdfAsync(List<IFormFile> streams, bool landscape) {38 s_browser ??= await Puppeteer.LaunchAsync(_browserOptions);39 var tasks = streams.Select(async x => {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

Service.cs

Source:Service.cs Github

copy

Full Screen

...38 await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });39 await using var page = await browser.NewPageAsync();40 await page.EmulateMediaTypeAsync(MediaType.Screen);41 await page.SetContentAsync(html);42 await page.PdfAsync("Invoice.pdf", new PdfOptions43 {44 Format = PaperFormat.A4,45 PrintBackground = true46 });47 });48 }49 }50}...

Full Screen

Full Screen

PdfHelper.cs

Source:PdfHelper.cs Github

copy

Full Screen

...23 Height = 50024 });25 await page.GoToAsync("http://www.google.com");26 var result = await page.GetContentAsync();27 await page.PdfAsync(outputFile);28 }29 }30}...

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });10 var page = await browser.NewPageAsync();11 await page.PdfAsync("1.pdf");12 await browser.CloseAsync();13 }14 }15}

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1var browserFetcher = new BrowserFetcher();2await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);3var browser = await Puppeteer.LaunchAsync(new LaunchOptions4{5 Args = new string[] { "--no-sandbox" }6});7var page = await browser.NewPageAsync();8await page.PdfAsync("google.pdf");9await browser.CloseAsync();10var browserFetcher = new BrowserFetcher();11await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);12var browser = await Puppeteer.LaunchAsync(new LaunchOptions13{14 Args = new string[] { "--no-sandbox" }15});16var page = await browser.NewPageAsync();17await page.PdfAsync("google.pdf");18await browser.CloseAsync();19var browserFetcher = new BrowserFetcher();20await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);21var browser = await Puppeteer.LaunchAsync(new LaunchOptions22{23 Args = new string[] { "--no-sandbox" }24});25var page = await browser.NewPageAsync();26await page.PdfAsync("google.pdf");27await browser.CloseAsync();28var browserFetcher = new BrowserFetcher();29await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);30var browser = await Puppeteer.LaunchAsync(new LaunchOptions31{32 Args = new string[] { "--no-sandbox" }33});34var page = await browser.NewPageAsync();35await page.PdfAsync("google.pdf");36await browser.CloseAsync();37var browserFetcher = new BrowserFetcher();38await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);39var browser = await Puppeteer.LaunchAsync(new LaunchOptions40{41 Args = new string[] { "--no-sandbox" }42});43var page = await browser.NewPageAsync();

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using PuppeteerSharp;7{8 {9 static async Task Main(string[] args)10 {11 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);12 var browser = await Puppeteer.LaunchAsync(new LaunchOptions13 {14 Args = new string[] { "--no-sandbox" }15 });16 var page = await browser.NewPageAsync();17 await page.PdfAsync("output.pdf");18 await browser.CloseAsync();19 }20 }21}

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2await page.PdfAsync("google.pdf");3var page = await browser.NewPageAsync();4await page.PdfAsync("google.pdf");5var page = await browser.NewPageAsync();6await page.PdfAsync("google.pdf");7var page = await browser.NewPageAsync();8await page.PdfAsync("google.pdf");9var page = await browser.NewPageAsync();10await page.PdfAsync("google.pdf");11var page = await browser.NewPageAsync();12await page.PdfAsync("google.pdf");13var page = await browser.NewPageAsync();14await page.PdfAsync("google.pdf");15var page = await browser.NewPageAsync();16await page.PdfAsync("google.pdf");17var page = await browser.NewPageAsync();18await page.PdfAsync("google.pdf");19var page = await browser.NewPageAsync();20await page.PdfAsync("google.pdf");

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Threading.Tasks;4using PuppeteerSharp;5using System.Threading;6{7 {8 static void Main(string[] args)9 {10 MainAsync().Wait();11 }12 static async Task MainAsync()13 {14 {15 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"16 };17 using (var browser = await Puppeteer.LaunchAsync(options))18 {19 using (var page = await browser.NewPageAsync())20 {21 await page.PdfAsync("C:\\Users\\Public\\Documents\\test.pdf");22 }23 }24 }25 }26}27using System;28using System.IO;29using System.Threading.Tasks;30using PuppeteerSharp;31using System.Threading;32{33 {34 static void Main(string[] args)35 {36 MainAsync().Wait();37 }38 static async Task MainAsync()39 {40 {41 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"42 };43 using (var browser = await Puppeteer.LaunchAsync(options))44 {45 using (var page = await browser.NewPageAsync())46 {47 await page.PdfAsync("C:\\Users\\Public\\Documents\\test.pdf");48 }49 }50 }51 }52}53using System;54using System.IO;55using System.Threading.Tasks;56using PuppeteerSharp;57using System.Threading;58{59 {60 static void Main(string[] args)61 {62 MainAsync().Wait();63 }64 static async Task MainAsync()65 {66 {67 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"68 };69 using (var browser = await Puppeteer.LaunchAsync(options))70 {

Full Screen

Full Screen

PdfAsync

Using AI Code Generation

copy

Full Screen

1var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3 Args = new[] { "--no-sandbox" }4});5var page = await browser.NewPageAsync();6await page.PdfAsync("C:\\Users\\user\\Desktop\\1.pdf");7var browser = await Puppeteer.LaunchAsync(new LaunchOptions8{9 Args = new[] { "--no-sandbox" }10});11var page = await browser.NewPageAsync();12await page.PdfAsync("C:\\Users\\user\\Desktop\\2.pdf");13var browser = await Puppeteer.LaunchAsync(new LaunchOptions14{15 Args = new[] { "--no-sandbox" }16});17var page = await browser.NewPageAsync();18await page.PdfAsync("C:\\Users\\user\\Desktop\\3.pdf");19var browser = await Puppeteer.LaunchAsync(new LaunchOptions20{21 Args = new[] { "--no-sandbox" }22});23var page = await browser.NewPageAsync();24await page.PdfAsync("C:\\Users\\user\\Desktop\\4.pdf");25var browser = await Puppeteer.LaunchAsync(new LaunchOptions26{27 Args = new[] { "--no-sandbox" }28});

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 Page

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful