Deployment to Azure Functions |
ExpertPdf Anywhere runs in Azure Functions (version 4, .NET isolated worker) on Windows and on Linux, on a Dedicated (App Service) plan of Basic or above, or on an Elastic Premium plan.
Plan | ExpertPdf Anywhere |
|---|---|
Dedicated (App Service), Basic or above | supported, Windows and Linux |
Elastic Premium (EP1 and up) | supported, Windows and Linux |
Consumption (Windows) | not supported |
Flex Consumption (Linux) | not supported |
A Windows Consumption plan cannot run the engine: the deployment does not fit the disk space the plan gives an application, Run From Package mounts the engine where it cannot be loaded, and the plan's sandbox stops the engine even when it is copied elsewhere. Flex Consumption always runs the application from the mounted, read-only package.
The same packages as a web application: ExpertPdf.Anywhere.Windows on Windows, or ExpertPdf.Anywhere.Linux and ExpertPdf.Anywhere.Fonts on Linux (or the managed ExpertPdf.Anywhere package with ExpertPdf.Anywhere.Native.win-x64 or ExpertPdf.Anywhere.Native.linux-x64).
1. Create a resource group, a storage account and a plan (--is-linux for Linux; --sku EP1 for Elastic Premium):
az login
az group create --name expertpdf-rg --location westeurope
az storage account create --resource-group expertpdf-rg \
--name expertpdfstorage --sku Standard_LRS
az functionapp plan create --resource-group expertpdf-rg \
--name expertpdf-fnplan --sku P1v3 --is-linux2. Create the function app on that plan, with Always On (a Dedicated plan option):
az functionapp create --resource-group expertpdf-rg \
--name expertpdf-fn --plan expertpdf-fnplan \
--storage-account expertpdfstorage --functions-version 4 \
--runtime dotnet-isolated --runtime-version 10 --os-type Linux
az functionapp config set --resource-group expertpdf-rg \
--name expertpdf-fn --always-on trueOn Windows use --os-type Windows and also pass --use-32bit-worker-process false to the second command.
3. Publish and deploy:
dotnet publish -c Release -o publish
cd publish && zip -r ../fn.zip . && cd ..
az functionapp deployment source config-zip --resource-group expertpdf-rg \
--name expertpdf-fn --src fn.zipA function app on a Dedicated plan does not use Run From Package, and the zip deployment does not turn it on, so the engine runs from a writable folder as in a web application. Do not set WEBSITE_RUN_FROM_PACKAGE (see Azure App Service).
A function that converts the page given in the query string:
[Function("Convert")] public static HttpResponseData Run( [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req) { string url = HttpUtility.ParseQueryString(req.Url.Query)["url"]; PdfConverter pdfConverter = new PdfConverter(); byte[] pdf = pdfConverter.GetPdfBytesFromUrl(url); HttpResponseData response = req.CreateResponse(HttpStatusCode.OK); response.Headers.Add("Content-Type", "application/pdf"); response.Body.Write(pdf, 0, pdf.Length); return response; }
The ExpertPdf Anywhere samples include a complete Azure Functions project for Windows and for Linux (windows/Functions, linux/Functions).
Function apps run on the same machines as web applications, so the plan advice of Azure App Service applies: choose Premium v3 when conversion time matters, and Basic or Standard for occasional or background conversions.