具有Multi-Col Newpaper布局的Rotativa ActionAsPdf

时间:2017-12-05 22:31:23

标签: html css3 pdf multiple-columns rotativa

在MVC 6中使用Rotativa 1.6.3使用ActionAsPdf从View生成PDF。

目的是使用CSS3 multi-col生成报纸样式报告,这可以使用chrome中的打印功能(参见图像所需的输出)

我试图在CSS中使用work arround,将列数替换为:

-webkit-column: 0 0;
width:50%

这项工作arround会生成列,但流程在分页符时不会改变,它只适用于第一页。

HTML

<body>
<div class="newspaper">
<P>
    Sed ut perspiciatis e quam nihil ............. molestiae consequatur, vel illum qui 
dolorem eum fugiat quo voluptas nulla pariatur? 
 </P>
<P>
    Sed ut perspiciatis e quam nihil ............. molestiae consequatur, vel illum qui 
dolorem eum fugiat quo voluptas nulla pariatur? 
 </P>
</div>
</body>

CSS

.newspaper 
{
-moz-column-count: 2; /*  Firefox */
-moz-column-gap: 10px; /*  Firefox */
-moz-column-rule-style: solid; /* Firefox */
-webkit-column-count: 2; /* Chrome, Safari, Opera */
-webkit-column-gap: 10px; /* Chrome, Safari, Opera */
-webkit-column-rule-style: solid; /* Chrome, Safari, Opera */
-webkit-column-rule-width: 1px;
column-count: 2;
column-gap: 10px;
column-rule-style: solid;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
padding-left: 5px;
padding-right: 5px;
}
.newspaper > p 
{
-webkit-column-break-inside: avoid; /* For Chrome & friends. */
break-inside: avoid !important; /* For standard browsers like IE. :-) */
overflow: hidden; /* fix for Firefox */
/* text-indent: 0em;  To show paragraph starts. */
page-break-inside: avoid; /* For Firefox. */
}

控制器:

public ActionResult PDFdetailreport4bit(int id)
    {
        //need to pass cookies to authenticate Rotativa
        Dictionary<string, string> cookieCollection = new Dictionary<string, string>();
        foreach (var key in Request.Cookies.AllKeys)
        {
            cookieCollection.Add(key, Request.Cookies.Get(key).Value);
        }

        AshPlant ashPlant = db.AshPlants.Find(id);

        string filename = "Ash Report";

        if (ashPlant != null)
        {
            filename = filename + " - " + ashPlant.Plant.Plant_Name + " - " + ashPlant.Description;
        }


        string footer = "--footer-center \"Printed on: " +
                        DateTime.Now.Date.ToString("MM/dd/yyyy") +
                        "  Page: [page]/[toPage]\"" +
                        " --footer-line --footer-font-size \"9\" --footer-spacing 6 --footer-font-name \"calibri light\"";

        return new ActionAsPdf("AshDetailReport4bit", new { id })
        {
            FileName = filename + ".pdf",
            CustomSwitches = footer,
            PageSize = Size.Letter,
            PageMargins = new Rotativa.Options.Margins(15, 10, 15, 10),
            //PageMargins = new Margins(0, 0, 0, 0),
            PageOrientation = Orientation.Portrait,
            Cookies = cookieCollection
        };
    }

输出PDF:

enter image description here

所需结果:( Chrome打印为PDF格式)

enter image description here

0 个答案:

没有答案