4

I have one reports, and it usually works in localhost with css. But when I put on the server does not load css with bundle.

code :

public ActionResult ParseSendPDF()
{
    var result = Session["Search"] as List<Order>;
    ViewAsPdf pdf = new ViewAsPdf("SendPDF", result);
    pdf.PageOrientation = Rotativa.Options.Orientation.Landscape;
    pdf.PageSize = Rotativa.Options.Size.A4;
    pdf.CustomSwitches = "--background";
    foreach (var results in result)
    {
        foreach (var detail in results.OrderDetails)
        {
             var description = detail.Description;
             if (description.Length > 84)
             {
                 SetBreakLine(ref description);
                 detail.Description = description;
             }
        }
    }
    return pdf;
}

View :

@model List<Models.Order>
@{
    Layout = null;
 }

 <!DOCTYPE html>
 <html>
 <head>
    <meta name="viewport" content="width=device-width" />
    <title>Reports</title>
    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/trip")
    @Styles.Render("~/Content/datetimepicker")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/ajax")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/datetimepicker") 
    <style type="text/css">
        table { page-break-inside:auto }
        tr    { page-break-inside:avoid; page-break-after:auto }
        thead { display:table-header-group }
        tfoot { display:table-footer-group }
    </style>
</head>
<body>
    <img style="margin-top: -7px;" class="img-responsive"    src="~/Content/Images//logo.png" />
    <h1 class="text-center">Reports</h1>
    @Html.Partial("_Index", Model)
</body>
</html>

In localhost working but in server, my css and logo not working.

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76

3 Answers3

5

I have spent weeks fighting this issue and I have tried every suggestion Stack Overflow offered:

  • Provided custom switches with a username and password for a user created on the IIS Server
  • Provided custom switches with a username and password for a user created on the Active Directory (since my application is authenticated through the Active Directory)
  • Adjusted permissions for all users to the wkhtmltopdf.exe on the IIS
  • Added both .min and normal css files to the bundle list
  • Adjusted permissions to the CSS files

In the end I finally removed the bundle reference and specifically stated my CSS file in my layout page header and it worked.

<link rel="stylesheet" type="text/css" href="~/Content/bootstrap.min.css"/>
meJustAndrew
  • 6,011
  • 8
  • 50
  • 76
Rachel Ostrander
  • 184
  • 2
  • 14
  • 1
    My code looks essentially the same as yours and my styles still aren't rendering in the report locally. I changed the view bundles to link tags like you did. The only thing I didn't do is modify permissions to the css files. I can't imagine that is the issue. I'm using Rotativa 1.6.4. – Brett Mathe Feb 20 '16 at 18:51
  • You placed them in the layout page or on the exact page you are trying to render? – Rachel Ostrander Feb 24 '16 at 14:00
  • It ended up being the physical path reference. – Brett Mathe Feb 25 '16 at 20:05
2

This situation can occur when your site uses windows authentication.

You need to give access to your CSS files in the web.config as follows:

<location path="content">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
ozz
  • 5,098
  • 1
  • 50
  • 73
0

Use Below code.. May this help you

@Styles.Render("@Server.MapPath(~/Content/css)")
@Styles.Render("@Server.MapPath("~/Content/trip)")
@Styles.Render("@Server.MapPath("~/Content/datetimepicker)")
@Scripts.Render("@Server.MapPath("~/bundles/jquery)")
@Scripts.Render("@Server.MapPath("~/bundles/ajax)")
@Scripts.Render("@Server.MapPath("~/bundles/modernizr)")
@Scripts.Render("@Server.MapPath("~/bundles/datetimepicker)") 
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118