惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

博客园 - 小马过河MJ

Identity Server introspect 调用 /connect/introspect windows forget jenkins password. 转载(Asp.net Core 中试使用ZKWeb.System.Drawing) EFCore & Mysql migration on Production Log4net 为MVC 添加下载权限 辞职 MiniProfiler Android Studio 设置LogCat 颜色 运用Swagger 添加WebAPI 文档 给现有MVC 项目添加 WebAPI Summernote async await 跨域调用WebApi MVC 伪静态 设置EntityFramework 在开发时自动更新数据库 PagedList.MVC 应用 MVC 自定义错误处理 SQL Server 索引结构及其使用(四)[转] SQL Server 索引结构及其使用(三)[转]
HTML to PDF pechkin
小马过河MJ · 2017-03-16 · via 博客园 - 小马过河MJ

1. Goto Nuget 下载 Pechkin 控件

2. 创建需要打印的的PDF controller 和 Action, 这里会调用其他页面的内容进行打印。

  public ActionResult ExportPDF(int id=0)
        {
            SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig()
                .SetMargins(new Margins() { Left = 0, Right = 0, Top = 0, Bottom = 0 })); //设置边距

            ObjectConfig oc = new ObjectConfig();

            string sCurrentUrl = Request.Url.ToString();
            string sBook = sCurrentUrl.Substring(0, sCurrentUrl.IndexOf("/Book"));
            string sPath = sBook + "/Book/BookToPdf/" + id;

            oc.SetPrintBackground(true).SetRunJavascript(true).SetScreenMediaType(true)
                .SetLoadImages(true)
                .SetPageUri(sPath);

            byte[] buf = sc.Convert(oc);

            return File(buf, "application/pdf", "download.pdf");

        }

  3. 调用页面代码

 public ActionResult BookToPdf(int id=0)
        {
            BookService BookBS = new BookService();
            var sModel = BookBS.GetBook(id);
            ViewData["BookModel"] = sModel;
            return View();
        }
@model List<LibrarySys.Web.Models.BookModel>

@{ 
    Layout = null;
}

<table class="table table-hover table-bordered">
    <thead>
        <tr>
            <td class="col-md-1">
                <p>图书编码</p>
                <p>出版日期</p>
            </td>
            <td>名称</td>
            <td>价格</td>
            <td class="col-md-1">作者</td>
            
            <td>出版社</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <p>@item.BookNumber</p>
                    <p>@item.BookPublish.ToShortDateString()</p>
                </td>
                <td><a href="/Book/BookEdit/@item.BookId" target="_self">@item.BookName</a></td>
                <td>@item.BookPrice</td>
                <td>@item.BookAuthor</td>
               
                <td>@item.Publisher</td>
                <td><a href="/Book/ExportPDF/@item.BookId" class="btn btn-xs btn-primary">导出PDF</a></td>
            </tr>
        }
    </tbody>
</table>

  4. 打印预览

5. 部署网络时问题解决。

6.