保存PDF文件作为字节数组或使用Rotativa流 [英] Save PDF file as a byte array or stream using Rotativa

查看:850
本文介绍了保存PDF文件作为字节数组或使用Rotativa流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将HTML转换成使用Rotativa PDF格式,但我想在保存为一个字节数组或数据流,所以我可以很容易地将其连接到一个邮件什么的。我找到了解决办法<一href="http://stackoverflow.com/questions/11854642/how-do-i-intercept-the-output-stream-of-the-current-actionresult-in-net-mvc3#answer-15181523">here但该文件不能被任何PDF阅读器打开,因为它是不支持的格式或该文件已损坏。

I'm trying to convert html to a PDF using Rotativa but I want to save at as a byte array or a stream so I can easily attach it to a mail or something. I found a solution here but the file can't be opened by any PDF reader because it's not a supported format or the file is corrupted.

下面是另一个<一个href="http://stackoverflow.com/questions/11854642/how-do-i-intercept-the-output-stream-of-the-current-actionresult-in-net-mvc3#answer-23088261">solution在同一个线程,但我无法弄清楚什么是所需的参数传递给这一功能,我找不到任何文档Rotativa网上。

Here is another solution from the same thread but I can't figure out what is the required parameters to pass to this function and I couldn't find any documentation for Rotativa online.

推荐答案

我找到了解决办法<一href="http://stackoverflow.com/questions/26608729/how-to-save-rotativa-pdf-on-server#answer-28347657">here

            var actionPDF = new Rotativa.ActionAsPdf("YOUR_ACTION_Method", new { id = ID, lang = strLang } //some route values)
            {
                //FileName = "TestView.pdf",
                PageSize = Size.A4,
                PageOrientation = Rotativa.Options.Orientation.Landscape,
                PageMargins = { Left = 1, Right = 1 }
            };
            byte[] applicationPDFData = actionPDF.BuildPdf(ControllerContext);

这篇关于保存PDF文件作为字节数组或使用Rotativa流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆