标签: rotativa

Rotativa PDF生成在本地工作但不在IIS 7上工作

我有一个ASP.NET MVC 5应用程序.它有一个简单的形式,当用户提交它时,表单存储在缓存中,然后调用另一个控制器操作,此操作将模型作为PDF返回视图.

我没有必要在本地保存它,只是为了在浏览器中显示它,以便用户可以下载它.

也不需要数据库,这就是我将模型存储在缓存中的原因.

在本地,在Visual Studio 2013上,它工作正常.但是当我将它发布到IIS 7时,我得到了一个Unhandled Execution Error.这是我得到的堆栈跟踪:

 Unhandled Execution Error
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception:

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception …
Run Code Online (Sandbox Code Playgroud)

iis-7 rotativa asp.net-mvc-5

33
推荐指数
5
解决办法
2万
查看次数

如何在Rotativa生成的PDF中显示分页符

在我的ASP.NET MVC 4应用程序中,我有一个索引视图,其中嵌入了几个部分视图.我通过NuGet安装了Rotativa的最新版本1.6.1.现在我可以使用Rotativa将索引页打印到PDF.我想在每个局部视图后在PDF中有一个分页符.如何使用Rotativa实现这一目标?

我试图按照这个例子使用CustomSwitches,但似乎没有一个用于分页符.我用这篇文章来生成PDF

pdf asp.net-mvc rotativa

15
推荐指数
2
解决办法
2万
查看次数

Azure网站和wkhtmltopdf

因此,在开始我的天蓝色网站冒险之后,我在失望之后遇到了令人失望的"几乎"后悔采取天蓝色的路线......最新的:我的应用程序使用wkhtmltopdf(Rotativa)进行所有PDF生成.正如我现在在我的分期测试中发现的......那不起作用.根据网络上的大多数信息,azure网站无法运行.exe的.但是,我见过的大多数信息现在已经有2年了,我知道Azure开发速度很快.

现在是否有办法在天蓝色网站上运行wkhtmltopdf,或至少解决方法?我真的找不到像wkhtmltopdf这样的免费替代品似乎正在工作.(Itextsharp似乎不喜欢我的html,所以没有选择).

asp.net-mvc azure wkhtmltopdf azure-web-sites rotativa

15
推荐指数
2
解决办法
6279
查看次数

为什么Rotativa总是生成我的登录页面?它为什么慢?

我正在使用这个Rotativa 1.6.4代码示例从我的.NET MVC 5应用程序中的页面生成PDF.

public ActionResult PrintIndex()
{
    var a = new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
    a.Cookies = Request.Cookies.AllKeys.ToDictionary(k => k, k => Request.Cookies[k].Value);
    a.FormsAuthenticationCookieName = System.Web.Security.FormsAuthentication.FormsCookieName;
    a.CustomSwitches = "--load-error-handling ignore";
    return a;
}

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

    return View();
}
Run Code Online (Sandbox Code Playgroud)

它没有打印索引页面,而是打印我的登录页面.

一旦我修复了身份验证问题,即使使用,PDF生成也非常慢CustomSwitches.(几分钟)

上面的代码可能实际上适合你 - 它使用Cookies属性解决了身份验证问题,但对我来说这太慢了.

如何打印安全页面以及快速完成?

rotativa asp.net-mvc-5

13
推荐指数
2
解决办法
5174
查看次数

Rotativa ViewAsPDF CSS尺寸/尺寸

我使用Rotativa ViewAsPdf方法将ASP.Net MVC中的HTML视图渲染为PDF .我通过设置以下设置输出为A4尺寸,纵向和无边距:

new ViewAsPdf(MVCCfpFormatter.Members.Views.FlightPlansFullPagePrint, model)
                    {
                       // FileName = flightPlan.ListingItemDetailsModel.FlightDetails + ".pdf",
                        PageSize = Size.A4,
                        PageOrientation = Orientation.Portrait,
                        PageMargins = new Margins(0, 0, 0, 0),
                        PageWidth = 210,
                        PageHeight = 297
                    };
Run Code Online (Sandbox Code Playgroud)

然后在CSS中,我设置一个具有210mm宽度的元素,它应该扩展页面的整个宽度,但在输出PDF中,210mm宽度不是表示PDF的整个宽度而是更少.通过反复试验,生成的PDF的总宽度似乎在附近246mm.

任何想法为什么会发生这种情况?

asp.net-mvc asp.net-mvc-4 rotativa

10
推荐指数
2
解决办法
2万
查看次数

Rotativa和Bootstrap网格样式

我正在开发一个ASP.NET MVC 5项目并使用Rotativa从Razor视图生成PDF文档.

我似乎无法让Rotativa使用Bootstrap样式正确渲染视图.我正在尝试使用Bootstrap做得很好的简单网格布局来设置视图样式.没什么太花哨的.

这是我的Razor View的截图: 剃刀视图

这是PDF的屏幕截图: 生成的PDF

以下是我的观点:

@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>

    <div class="container">
        <h1>Hello World!</h1>
        <p>Resize the browser window to see the effect.</p>
        <div class="row">
            <div class="col-sm-6" style="background-color:lavender;">
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
                <p> Ut enim ad minim veniam, quis nostrud exercitation …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc pdf-generation twitter-bootstrap rotativa

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

如何在服务器上保存Rotativa PDF

我正在使用Rotativa在我的"MVC"应用程序中生成PDF.如何保存Rotativa PDF?所有过程完成后,我需要将文档保存在服务器上.

代码如下:

public ActionResult PRVRequestPdf(string refnum,string emid)
{
    var prv = functions.getprvrequest(refnum, emid);            
    return View(prv);

}
public ActionResult PDFPRVRequest()
{
    var prv = Session["PRV"] as PRVRequestModel;
    byte[] pdfByteArray = Rotativa.WkhtmltopdfDriver.ConvertHtml("Rotativa", "Approver", "PRVRequestPdf");
    return new Rotativa.ViewAsPdf("PRVRequestPdf", new { refnum = prv.rheader.request.Referenceno });            

} 
Run Code Online (Sandbox Code Playgroud)

rotativa asp.net-mvc-5

9
推荐指数
2
解决办法
2万
查看次数

Rotativa/Wkhtmltopdf图像无法显示

我目前正在创建一个MVC 4 Web应用程序.

我有一个基本背景图像的动作总是与箭头图像相同,箭头图像的度数会根据动作中收集的信息而改变.

我用这个动作来称呼

<img src="@Url.Action("trend-image", "NonReg_Reports")" alt="background" width="245" height="105" />
Run Code Online (Sandbox Code Playgroud)

这在调用时工作正常,只是显示HTML网页.它给了我HTML.

<img src="/nonreg-report/01495344/trend-image" alt="background" width="245" height="105">
Run Code Online (Sandbox Code Playgroud)

然后我使用Rotativa/Wkhtmltopdf将此HTML页面转换为PDF.这与上面的代码相同.

问题是如果我使用上面的代码,我只是得到一个带有替代文本的白框.

如果我使用<img src="~/Content/images/trend_back_medium.png" alt="astuff" />哪个是我项目中的实际背景图像,它可以正常工作.

由于使用方式,上面代码中的图像无法保存在任何地方.我认为这是一个路径问题,但在尝试了很多不同的事情后,我仍然无法让它发挥作用.

任何建议或帮助将不胜感激,谢谢.

asp.net-mvc image path wkhtmltopdf rotativa

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

Rotativa,ABCPdf和EO.Pdf在Azure WEBSITES中不起作用,我不想升级到Azure"Cloudapp"

鉴于环境问题(将其视为事实):

1)Rotativa PDF(https://github.com/webgio/Rotativa)使用exe来创建PDF,因此它不适用于azure网站(没有执行该exe的权限)

2)ABCPdf也有同样的问题

3)EO.Pdf有类似的问题("使用Windows GDI但Windows Azure WebSite不支持Windows GDI",http://www.essentialobjects.com/doc/4/install/deploy.aspx)

4)我不想拥有Azure Cloudapp(允许我使用Rotativa或ABCPdf).我的Azure网站很好(除了以前的问题).

有替代解决方案吗?
是否还有其他用于从HTML创建可以在Azure网站(不是CloudService或VM)上运行的PDF的库?




更新nov-2014:
我今天使用的是MvcRazorToPdf,非常棒.

控制器代码:

return new PdfActionResult(palletReception, (writer, document) =>
{
    document.SetPageSize(new Rectangle(792f, 612f));
    document.NewPage();
})
{
    FileDownloadName = "foo.pdf"
};
Run Code Online (Sandbox Code Playgroud)

查看代码:

A normal view with normal css.
Must be accepted by iText XMLWorker

Check this: http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html
and this: http://demo.itextsupport.com/xmlworker/
Run Code Online (Sandbox Code Playgroud)

pdf-generation abcpdf azure wkhtmltopdf rotativa

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

在MVC中使用Rotativa pdf显示动态标头

我想打印动态的标题数据,它将来自控制器.

那么如何使用Rotativa pdf在标题中显示动态数据.

我的标题数据包括名称,地址,联系信息和其他附加信息,这些信息是动态的,并从控制器端生成.

我使用html页面创建了带有静态头的pdf,如下所示

string header = Server.MapPath("~/Static/NewFolder/PrintHeader.html");
 string footer = Server.MapPath("~/Static/NewFolder/PrintFooter.html");

 string customSwitches = string.Format("--header-html  \"{0}\" " +
                        "--header-spacing \"0\" " +
                        "--footer-html \"{1}\" " +
                        "--footer-spacing \"10\" " +
                        "--footer-font-size \"10\" " +
                        "--header-font-size \"10\" ", header, footer);

return new ViewAsPdf("SchedulePrintPdf", modelData)
                    {
                        CustomSwitches = customSwitches,
                        PageOrientation = Orientation.Portrait,
                        PageMargins = { Top = 20, Bottom = 22 },
                        SaveOnServerPath = filePath, FileName = Path.GetFileName(fileName)
                    };
Run Code Online (Sandbox Code Playgroud)

这适用于Static标头.

现在我需要动态地从这个控制器发送标题文本.

pdf asp.net-mvc wkhtmltopdf rotativa

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