@@ -267,28 +267,28 @@ public static string ToUtcString(string? timestring)
267267 Headless = true
268268 } ) ;
269269
270- // try
271- // {
272- using IPage page = await browser . NewPageAsync ( ) ;
273- await page . SetContentAsync ( html ) ;
274-
275- // PuppeteerSharp.Media.PaperFormat? pupformat = GetPuppeteerPaperFormat(format) ?? throw new Exception();
276- PdfOptions pdfOptions = new ( ) { DisplayHeaderFooter = true , Landscape = true , PrintBackground = true , Format = PuppeteerSharp . Media . PaperFormat . A4 , MarginOptions = new MarginOptions { Top = "1cm" , Bottom = "1cm" , Left = "1cm" , Right = "1cm" } } ;
277- // PdfOptions pdfOptions = new() { DisplayHeaderFooter = true, Landscape = true, PrintBackground = true, Format = pupformat, MarginOptions = new MarginOptions { Top = "1cm", Bottom = "1cm", Left = "1cm", Right = "1cm" } };
278- using Stream ? pdfData = await page . PdfStreamAsync ( pdfOptions ) ;
279-
280- byte [ ] ? pdfWithToCData = AddToCBookmarksToPDF ( pdfData , html ) ;
281-
282- return Convert . ToBase64String ( pdfWithToCData ) ;
283- // }
284- // catch (Exception)
285- // {
286- // throw new Exception("This paper kind is currently not supported. Please choose another one or \"Custom\" for a custom size.");
287- // }
288- // finally
289- // {
290- // await browser.CloseAsync();
291- // }
270+ try
271+ {
272+ using IPage page = await browser . NewPageAsync ( ) ;
273+ await page . SetContentAsync ( html ) ;
274+
275+ PuppeteerSharp . Media . PaperFormat ? pupformat = GetPuppeteerPaperFormat ( format ) ?? throw new Exception ( ) ;
276+
277+ PdfOptions pdfOptions = new ( ) { DisplayHeaderFooter = true , Landscape = true , PrintBackground = true , Format = pupformat , MarginOptions = new MarginOptions { Top = "1cm" , Bottom = "1cm" , Left = "1cm" , Right = "1cm" } } ;
278+ using Stream ? pdfData = await page . PdfStreamAsync ( pdfOptions ) ;
279+
280+ byte [ ] ? pdfWithToCData = AddToCBookmarksToPDF ( pdfData , html ) ;
281+
282+ return Convert . ToBase64String ( pdfWithToCData ) ;
283+ }
284+ catch ( Exception )
285+ {
286+ throw new Exception ( "This paper kind is currently not supported. Please choose another one or \" Custom\" for a custom size." ) ;
287+ }
288+ finally
289+ {
290+ await browser . CloseAsync ( ) ;
291+ }
292292 }
293293
294294 private static List < ToCHeader > CreateTOCContent ( string html )
@@ -383,7 +383,6 @@ private static bool IsValidHTML(string html)
383383 private static byte [ ] AddToCBookmarksToPDF ( Stream pdfData , string html )
384384 {
385385 PdfDocument document = PdfReader . Open ( pdfData , PdfDocumentOpenMode . Modify ) ;
386- //XFont font = new("Verdana", 16);
387386
388387 PdfPage page = document . Pages [ 0 ] ;
389388
0 commit comments