@@ -17,48 +17,49 @@ public Function1(ILogger<Function1> logger)
1717 _logger = logger ;
1818 }
1919
20+
2021 [ Function ( "Function1" ) ]
21- public async Task < IActionResult > Run ( [ HttpTrigger ( AuthorizationLevel . Function , "get" , "post" ) ] HttpRequest req )
22- {
2322
24- MemoryStream ms = new MemoryStream ( ) ;
23+ public IActionResult Run ( [ HttpTrigger ( AuthorizationLevel . Anonymous , "get" , "post" ) ] HttpRequest req )
24+ {
25+ string blinkBinariesPath = string . Empty ;
26+ MemoryStream ms = null ;
2527 try
2628 {
27- //Initialize HTML to PDF converter.
29+
30+ //Initialize the HTML to PDF converter with the Blink rendering engine.
2831 HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter ( HtmlRenderingEngine . Cef ) ;
29- CefConverterSettings settings = new CefConverterSettings ( ) ;
30- //Assign WebKit settings to HTML converter.
31- htmlConverter . ConverterSettings = settings ;
32- //Convert URL to PDF.
32+ //Convert URL to PDF
3333 PdfDocument document = htmlConverter . Convert ( "https://www.google.com/" ) ;
34- //Save and close the PDF document.
34+
35+ ms = new MemoryStream ( ) ;
36+ //Save and close the PDF document
3537 document . Save ( ms ) ;
3638 document . Close ( ) ;
37- ms . Position = 0 ;
3839 }
39-
4040 catch ( Exception ex )
4141 {
4242 //Create a new PDF document.
4343 PdfDocument document = new PdfDocument ( ) ;
4444 //Add a page to the document.
4545 PdfPage page = document . Pages . Add ( ) ;
46+
4647 //Create PDF graphics for the page.
4748 PdfGraphics graphics = page . Graphics ;
48-
4949 //Set the standard font.
50- PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 5 ) ;
50+ PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 20 ) ;
5151 //Draw the text.
52- graphics . DrawString ( ex . ToString ( ) , font , PdfBrushes . Black , new Syncfusion . Drawing . PointF ( 0 , 0 ) ) ;
52+ graphics . DrawString ( ex . Message , font , PdfBrushes . Black , new Syncfusion . Drawing . PointF ( 0 , 0 ) ) ;
5353
5454 //Creating the stream object.
5555 ms = new MemoryStream ( ) ;
5656 //Save the document into memory stream.
5757 document . Save ( ms ) ;
5858 //Close the document.
5959 document . Close ( true ) ;
60- ms . Position = 0 ;
60+
6161 }
62+ ms . Position = 0 ;
6263 return new FileStreamResult ( ms , "application/pdf" ) ;
6364 }
6465 }
0 commit comments