Skip to content

for ASP.NET Core on Azure Web Apps (by Windows). Support .NETStandard 2.0

License

Notifications You must be signed in to change notification settings

shekky/RotativaCore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extremely easy way to create Pdf files from ASP.NET Core

New Features

  • Support new event. OnBuildFileSuccess()
        public ActionResult TestInlie()
        {
            return new ActionAsPdf("Index", new { name = "Friends" })
            {
                //FileName = "Test.pdf",
                ContentDisposition = ContentDisposition.Inline,
                OnBuildFileSuccess = async (bytes, context, fileName) =>
                {
                    // some code done.
                    return true;

                    // example.
                    if (string.IsNullOrEmpty(fileName))
                        fileName = $"{Guid.NewGuid()}.pdf";

                    var container = CloudStorageAccount
                         // Please set your value.
                         // If it's null, it will result in an ArgumentNullException().
                        .Parse(connectionString:null)
                        .CreateCloudBlobClient()
                        // Please set your value.
                        // If it's null, it will result in an ArgumentNullException().
                        .GetContainerReference(containerName:null);

                    try
                    {
                        var blockBlob = container.GetBlockBlobReference(fileName);
                        blockBlob.Properties.ContentType = "application/pdf";
                        await blockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);
                    }
                    catch (Exception e)
                    {
                        // logging.
                        return false;  // fire InvalidOperationException()
                    }

                    return true;
                },
            };
        }

Usage

public ActionResult PrintIndex()
{
    return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
}

public ActionResult Index(string name)
{
    ViewBag.Message = string.Format("Hello {0} to ASP.NET MVC!", name);

    return View();
}

ViewAsPdf now available. It enables you to render a view as pdf in just one move, thanks to scoorf

public ActionResult TestViewWithModel(string id)
{
    var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
    return new ViewAsPdf(model);
}

Also available a RouteAsPdf, UrlAsPdf and ViewAsPdf ActionResult.

It generates Pdf also from authorized actions (web forms authentication).

You can also output images from MVC with ActionAsImage, ViewAsImage, RouteAsImage, UrlAsImage.

About

for ASP.NET Core on Azure Web Apps (by Windows). Support .NETStandard 2.0

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.5%
  • CSS 1.5%