简体   繁体   中英

How to generate PDF with Rotativa including charts from C3JS Asp.net

I'm working on dashaboard stats on one of my projects, and I'm using the C3js to add charts to my dashboard, and all it works fine,

but when I wanna generate a pdf of this dashboard using Rotativa Plugin and wkhtmltopdf, but it doesn't work properly, it generates a pdf with data but not showing charts.

Conf Application:

Server-Side : ASP.Net MVC5

Client-Side :Javascript, Rotativa, C3js

In my similar situation, I found that Rotiva wasn't going out and getting all my included files, and/or was taking too long.

So I decided what was vital, and put that into a "static layout" that contained everything I needed inline. This might include CSS files you need to render correctly, or javascript files that you include. If you go to those files, you can copy and paste their contents into style or script tag in this Static Layout, and now Rotativa will have those payloads without having to go and get them.

//Layout Static
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
    <head>
        <title>@ViewBag.Title</title>
        <meta charset="utf-8" />

        <style type="text/css">
            body {
                color: white;
            }
            /*Whatever style info needed*/
        </style>

        <script type="text/javascript">
            /*Whatever code needed*/
        </script>
    </head>
    <body>
        <div class="container">
            @RenderBody()
        </div>
    </body>
</html>

I put this into a Layout that replaced my standard Layout just for the rotiva exporting views.

Then, I made a copy of the view for rotativa PDF output, where it used this static layout.

@model SomeModel
@{
    ViewBag.Title = "Some Title";
    Layout = "~/Views/Shared/_LayoutStatic.cshtml";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM