Rotativa ActionAsPdf with Multi-Col Newpaper layout
Asked Answered
S

0

6

Using Rotativa 1.6.3 in MVC 6 to generate PDF from View using ActionAsPdf.

The intention is to generate a Newspaper style report using CSS3 multi-col, this works using the print function in chrome (see image desired output)

I have tried to use a work arround in the CSS, by replacing column count with:

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

This work arround generates columns however the flow does not change on page breaks and it only works on the first page.

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. */
}

Controller:

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
        };
    }

Output PDF:

enter image description here

Desired Result: (Chrome print as PDF)

enter image description here

Southey answered 5/12, 2017 at 22:31 Comment(3)
Did you ever figure this out? I'm having the same kinda problemMethodize
Oh look i'm having same problem, guess this plugin doesn't do the job...Combustion
anyone found a solution to this?Adorn

© 2022 - 2024 — McMap. All rights reserved.