Azure Function Appsには3つの異なる環境があります:Linux、Windows、Container。 この記事では、3つのすべての環境でIronPdfを設定する方法を説明します。 これらの中で、Azure Function App Containerは推奨されます。それは分離された環境を提供するためです。 まず、インストールする適切なパッケージを選びましょう。
Azure Function App コンテナ
Azure Function App Containerには手間がほとんどかからないため、IronPDFをデプロイする推奨方法です。
IronPdf.Linuxパッケージ
<div class="copy-nuget-section md-body net" data-toggle="tooltip" data-placement="top" data-copy-text="Click to copy" data-copied-text="Copied to clipboard" data-bs-original-title=""クリップボードにコピーされました"" data-bs-title=""クリップボードにコピーされました"">
[FunctionName("PrintPdf")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("Entered PrintPdf API function...");
// Apply license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
// Enable log
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
IronPdf.Logging.Logger.CustomLogger = log;
// Configure IronPdf
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true;
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
IronPdf.Installation.CustomDeploymentDirectory = "/tmp";
try
{
log.LogInformation("About to render pdf...");
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render PDF
var pdf = renderer.RenderUrlAsPdf("https://www.google.com/");
log.LogInformation("finished rendering pdf...");
return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" };
}
catch (Exception e)
{
log.LogError(e, "Error while rendering pdf", e);
return new OkObjectResult($"Error while rendering pdf: {e}");
}
}
[FunctionName("PrintPdf")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("Entered PrintPdf API function...");
// Apply license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";
// Enable log
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
IronPdf.Logging.Logger.CustomLogger = log;
// Configure IronPdf
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true;
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
IronPdf.Installation.CustomDeploymentDirectory = "/tmp";
try
{
log.LogInformation("About to render pdf...");
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render PDF
var pdf = renderer.RenderUrlAsPdf("https://www.google.com/");
log.LogInformation("finished rendering pdf...");
return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" };
}
catch (Exception e)
{
log.LogError(e, "Error while rendering pdf", e);
return new OkObjectResult($"Error while rendering pdf: {e}");
}
}
<FunctionName("PrintPdf")>
Public Shared Async Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger, ByVal context As ExecutionContext) As Task(Of IActionResult)
log.LogInformation("Entered PrintPdf API function...")
' Apply license key
IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"
' Enable log
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom
IronPdf.Logging.Logger.CustomLogger = log
' Configure IronPdf
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True
IronPdf.Installation.AutomaticallyDownloadNativeBinaries = True
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled
IronPdf.Installation.CustomDeploymentDirectory = "/tmp"
Try
log.LogInformation("About to render pdf...")
Dim renderer As New ChromePdfRenderer()
' Render PDF
Dim pdf = renderer.RenderUrlAsPdf("https://www.google.com/")
log.LogInformation("finished rendering pdf...")
Return New FileContentResult(pdf.BinaryData, "application/pdf") With {.FileDownloadName = "google.pdf"}
Catch e As Exception
log.LogError(e, "Error while rendering pdf", e)
Return New OkObjectResult($"Error while rendering pdf: {e}")
End Try
End Function
Azureの無料および共有レベル、または従量課金プランは、PDFレンダリングには適していません。 私たちは、自分たち自身で使用しているAzure B1ホスティング/プレミアムプランを推奨します。 HTML から PDF への変換プロセスは、あらゆるコンピューターにとって重要な「仕事」です。これは、あなた自身のマシンでウェブページを開いてレンダリングすることに似ています。実際のブラウザエンジンが使用されるため、それに応じてプロビジョニングする必要があり、同様の性能を持つデスクトップマシンのレンダリング時間と同程度の時間がかかると予想されます。