Skip to main content Skip to footer

How to deploy a PDF API to Azure in 6 steps

GrapeCity Documents for PDF is a high-speed, low-footprint PDF document API that allows you to generate, modify, load, and save PDFs easily in your .NET apps. For your cloud-based apps, here's how to deploy GC Docs for PDF in your Azure apps in 6 steps.

Step 1: Create a new ASP.NET Core MVC app

First, in Visual Studio, go to File > New > Project, and select ASP.NET Core Web Application. In the wizard that opens, select Web Application (Model-View-Controller).

Step 2: Add reference to GrapeCity.Documents.Pdf

Next, go to Dependencies > Manage NuGet Packages, and install the GrapeCity.Documents.Pdf package.

Step 3: Clean up the Index.cshtml page

Clean up the Index.cshtml page so that it contains only this code. This step is optional, as our controller will send PDF content for this page.

@{
    ViewData["Title"] = "Home Page";
}
<div class="row">
</div>

Step 4: Modify HomeController.cs

Modify HomeController.cs to generate the 'Hello, World!' PDF. The code should look like this:

using System.Drawing;
using System.IO;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;

Modify the Index() method like so:

public IActionResult Index()
{
    // Create the 'Hello, World!' PDF:
    var doc = new GcPdfDocument();
    var page = doc.NewPage();
    var g = page.Graphics;
    g.DrawString("Hello, World!", new TextFormat() { Font = StandardFonts.Times }, new PointF(72, 72));

    // Save it to a memory stream:
    MemoryStream ms = new MemoryStream();
    doc.Save(ms);
    ms.Seek(0, SeekOrigin.Begin);

    // Send it back to the web page:
    Response.Headers["Content-Disposition"] = "inline; filename=\"HelloWorld.pdf\"";
    return new FileStreamResult(ms, "application/pdf");
}

Step 5: Try it

From Visual Studio, run your app locally to make sure everything works. You should see the "Hello, World!" PDF opening in your default web browser.

Step 6: Publish the app to Azure

Finally, go to to Build > Publish, create a new 'Microsoft Azure App Service' publish profile, select the appropriate name, subscription details, etc.; the defaults should work just fine.

Get the code to publish PDF API to Azure

Try GrapeCity Documents for PDF

Dmitry Yaitskov

comments powered by Disqus