To test this function in the azure portal you simply need to post some HTML in the request body. For example:
<title>Title</title> Body text... "-
-
Save GuyHarwood/f578109244d887874cc1c948c40bd184 to your computer and use it in GitHub Desktop.
Create PDF Rendering service in Azure Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bindings": [ | |
{ | |
"authLevel": "function", | |
"name": "req", | |
"type": "httpTrigger", | |
"direction": "in" | |
}, | |
{ | |
"name": "$return", | |
"type": "http", | |
"direction": "out" | |
} | |
], | |
"disabled": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"frameworks": { | |
"net46":{ | |
"dependencies": { | |
"OpenHtmlToPdf": "1.12.0" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
using System.Net.Http.Headers; | |
using OpenHtmlToPdf; | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info("Processing PDF Request"); | |
string html = await req.Content.ReadAsStringAsync(); | |
var pdf = Pdf | |
.From(html) | |
.Content(); | |
log.Info($"PDF Generated. Length={pdf.Length}"); | |
var res = new HttpResponseMessage(HttpStatusCode.OK); | |
res.Content = new ByteArrayContent(pdf); | |
res.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); | |
res.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline"); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment