标签: rotativa

使用Rotativa预览pdf而不是下载

我正在尝试使用Rotativa .html.pdf文件打印为文件.我试过这段代码:

return new ActionAsPdf("Index") { FileName = "Product.pdf" };
Run Code Online (Sandbox Code Playgroud)

我的索引操作在这里:

public ActionResult Index()
{
    return View(db.Products.ToList());
}
Run Code Online (Sandbox Code Playgroud)

但是,生成的.pdf文件是下载而不是预览的.我不想下载它.我想要预览然后打印它.

c# asp.net-mvc rotativa

3
推荐指数
1
解决办法
3480
查看次数

Rotativa PDF导出 - 无法同时显示内联和文件名

我发现Rotativa是一种轻松导出为PDF的方法(除了CSS3之外几乎完全没有支持,可能在将来的版本中使用)...但我想知道如何处理该FileName选项.

当我

return new Rotativa.ViewAsPdf("myViewName", "~/Views/Shared/_PDFLayout.cshtml", myModel)
{
    FileName = "myCorrectlyNamed.pdf",
    PageSize = ... // plus some more options
};
Run Code Online (Sandbox Code Playgroud)

然后我会myCorrectlyNamed.pdf下载.当我省略该FileName选项时,PDF将显示在浏览器中,但是当我从那里保存时,它只有默认文件名document.pdf.

如何在浏览器中生成和显示pdf,并且文件名不是document.pdf从那里保存的?

asp.net-mvc rotativa

3
推荐指数
1
解决办法
910
查看次数

Rotativa PDF MVC3 分页

我正在使用Rotativa在我的 mvc4 应用程序中创建 pdf。问题是如何在 pdf 上显示页码。

c# asp.net-mvc-4 rotativa

2
推荐指数
1
解决办法
8328
查看次数

如何将复杂模型传递给 ActionAsPDF?

我正在创建一个 MVC 4 应用程序。我正在使用 Rotativa 生成 pdf

他们有一个方法叫做

public ActionAsPdf(string action, object routeValues);
Run Code Online (Sandbox Code Playgroud)

我在将复杂对象传递给 routeValues 时遇到问题

IE:

我有一个视图模型

public class FullName
{
    public string FirstName { get; set; }
    public string Surname { get; set; }
}

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

public ActionResult Test()
{
    var fullname = new FullName();
    fullname.FirstName = "John";
    fullname.Surname = "Smith";

    return new ActionAsPdf("Index", new { name = fullname }) { FileName = …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-4 rotativa

2
推荐指数
1
解决办法
8275
查看次数

我正在使用Rotativa工具来显示pdf.它在localhost上工作正常,但在Azure平台上不起作用

Rotativa tool用来显示PDF.它工作正常localhost,但不适用于Azure平台.

以下是我的代码......

public ActionResult GeneratePDF(int id = 0)
    {
        ReportTransactionData reporttransactiondata = db.ReportTransactionDatas.Find(id);
        var viewFileToPrint = @"~/Views/ReportTranData/PDFReport.cshtml";
        //var oRotativaPDF = new Rotativa.ViewAsPdf();
        var oRotativaPDF = new Rotativa.PartialViewAsPdf();
        try
        {
            if (reporttransactiondata == null)
            {
                return HttpNotFound();
            }
            else
            {
                // Populate reporttransactiondata with Verfier Name...TO BE IMPLEMENTED LATER...
                //reporttransactiondata.VerifierName = GetVerifierNameByID(reporttransactiondata.VerifierID);
            }

            // Code to call a function/action...
            //return new Rotativa.ActionAsPdf("PrintRptInPDF", reporttransactiondata) 

            //oRotativaPDF = new Rotativa.ViewAsPdf(viewFileToPrint, reporttransactiondata)
            //        {
            //            FileName = "Technician …
Run Code Online (Sandbox Code Playgroud)

pdf model-view-controller azure rotativa

2
推荐指数
1
解决办法
6614
查看次数

Rotativa.Netcore 在本地工作但在部署后不工作

我在 ASP.NET Core 2.1.1 项目中使用最新的 Rotativa.NetCore 程序集。NuGet ( https://www.nuget.org/packages/Rotativa.AspNetCore v. 1.0.6 ) 在部署 (win2016) 上不起作用,但在本地运行 (win10)。

IIS 在部署时给出 404,错误日志 (stdout) 显示:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.Exception
   at Rotativa.AspNetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe)
   at Rotativa.AspNetCore.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html)
   at Rotativa.AspNetCore.ViewAsPdf.CallTheDriver(ActionContext context)
   at Rotativa.AspNetCore.AsResultBase.BuildFile(ActionContext context)
   at Rotativa.AspNetCore.AsResultBase.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at …
Run Code Online (Sandbox Code Playgroud)

c# rotativa asp.net-core

2
推荐指数
1
解决办法
4063
查看次数

Rotativa无法对空引用asp.net核心执行运行时绑定

问题

我正在尝试使用Rotativa在asp.net核心中创建pdf,但它给我一个错误.我想创建html并将其转换为pdf,然后存储在服务器目录中

错误

在此输入图像描述

[HttpPost]
    public IActionResult Index(Invoice invoice)
    {
        var webRoot = _env.WebRootPath;

        var pdf = new ViewAsPdf("Index")
        {
            FileName = "Test.pdf",
            PageSize = Rotativa.AspNetCore.Options.Size.A4,
            PageOrientation = Rotativa.AspNetCore.Options.Orientation.Portrait,
            PageHeight = 20,

        };

        var byteArray = pdf.BuildFile(ControllerContext).Result;
        //var fileStream = new MemoryStream(Path.Combine(webRoot, pdf.FileName), FileMode.Create, FileAccess.Write);
        var memoryStream = new MemoryStream(byteArray, 0, byteArray.Length);
    }
Run Code Online (Sandbox Code Playgroud)

c# rotativa asp.net-core

2
推荐指数
1
解决办法
420
查看次数

asp.net core 3 rotativa startup.cs 环境问题

我尝试使用 Rotativa ?m 按照 start.cs 中的本指南在配置函数中添加此代码

  RotativaConfiguration.Setup(env);
Run Code Online (Sandbox Code Playgroud)
Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' to 'Microsoft.AspNetCore.Hosting.IHostingEnvironment'    
Run Code Online (Sandbox Code Playgroud)

?m 搜索此错误并找到它并像这样转换我的代码

 RotativaConfiguration.Setup(env.WebRootPath, "Rotativa");
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.AspNetCore.Hosting.IHostingEnvironment'  

Run Code Online (Sandbox Code Playgroud)

?m 在 wwwroot 中添加 Rotative 文件夹并添加 wkhtmltoimage.exe、wkhtmltopdf.exe

我的包版本 Rotativa.aspnetcore v1.1.1 ?m 使用当前的 asp.net 核心版本 3.xx 有什么问题有人可以解释我吗?

rotativa asp.net-core-3.0 asp.net-core-3.1

2
推荐指数
1
解决办法
4201
查看次数

如何将复杂模型传递给 Rotativa?

我正在使用 MVC 4 创建应用程序。我正在使用 Rotativa 创建 pdf。我正在使用复杂模型调用 ActionAsPdf

我的模型是

public class BrandingDetails
    {
        public int PDFFileNo { get; set; }
        public string LogoImageUrl { get; set; }
        public string WebsiteUrl { get; set; }
        public string PhoneNumber_AU { get; set; }
        public string PhoneNumber_NZ { get; set; }
        public string FacebookImageUrl { get; set; }
        public string TwitterImageUrl { get; set; }
        public string PinterestImageUrl { get; set; }
        public string YoutubeImageUrl { get; set; }
        public string CruiseCode { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-4 rotativa

1
推荐指数
1
解决办法
3776
查看次数

使用Rotativa生成PDF从页面中断数据的视图继续在第二页的标题上继续忽略CSS

我已经尝试了很多答案,并与结论没有甚至开发商自己,我有得到由一个复杂的模块中创建一个索引页答案出来了,视图接收与ActionAsPdf模块,并产生除了当页的PDF打破表继续在下一页覆盖表头顶部的记录.

public ActionResult PrintRoster(Guid id)
    {
        string footer = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";

        return new ActionAsPdf("RosterPDF", 
                            new { id = id }) { FileName = "ClassRoster.pdf",
                                                PageSize = Rotativa.Options.Size.A4,
                                                PageOrientation = Rotativa.Options.Orientation.Portrait,
                                                MinimumFontSize = 16,
                                                PageMargins = {Top = 15, Bottom = 22},
                                                PageHeight = 40,
                                                CustomSwitches = footer
                            };
    }
Run Code Online (Sandbox Code Playgroud)

创建RosterPDF然后生成有问题的PDF

@model Training.ViewModels.RosterViewModel
@using Training.UtilModels
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head> …
Run Code Online (Sandbox Code Playgroud)

html-to-pdf rotativa asp.net-mvc-5

1
推荐指数
1
解决办法
5535
查看次数