将代码渲染为PDF格式 [英] Render code to PDF format

查看:61
本文介绍了将代码渲染为PDF格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai,



这是我的代码:



Hai,

This is my code:

DataTable dtDS = ds.Tables["tblDS"];
if (dtDS.Rows.Count != 0)
{
    DataRow dr = dtDS.Rows[0];

    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    LocalReport lr = viewer.LocalReport;
    lr.ReportPath = ConfigUtil.GetAppSetting("DataSheetType_" + dr["DataSheetType"].ToString());
    ReportDataSource rds = new ReportDataSource();
    rds.Value = ds.Tables[0];
    rds.Name = "report";

    HTMLConverter rtf = new HTMLConverter();

    if (dr["SO1_Address"].ToString() != "")
    {
        dr["SO1_Address"] = rtf.HTML2RTF(dr["SO1_Address"].ToString(), 16);
    }

    lr.DataSources.Add(rds);                        

    string reportType = "PDF";
    string mimeType = "application/pdf";
    string encoding;
    string fileNameExtension = Guid.NewGuid().ToString() + ".pdf";

    string deviceInfo =
    "<DeviceInfo>" +
    "  <OutputFormat>PDF</OutputFormat>" +                        
     "</DeviceInfo>";

    Warning[] warnings;
    string[] streams;
    byte[] renderedBytes;                        

    renderedBytes = lr.Render(
    reportType,
    deviceInfo,
    out mimeType,
    out encoding,
    out fileNameExtension,
    out streams,
    out warnings);

    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
    Response.BinaryWrite(renderedBytes);
    Response.End();
}





代码编译器在尝试执行lr.Render代码时返回异常。我不知道出了什么问题?



lr.ReportPath是一个rdlc报告文件。



The code compiler returns an exception while trying to execute the lr.Render code. I have no idea what's wrong?

lr.ReportPath is an rdlc report file.

推荐答案

使用此链接。你可以理解隐藏的格式,包括pdf格式。



http://www.aspsnippets.com/Articles/Export-DataSet-or-DataTable-to-Word-Excel- PDF-and-CSV-Formats.aspx [ ^ ]
Use this Link. You can understand the easy way of covert in to number of formats including pdf.

http://www.aspsnippets.com/Articles/Export-DataSet-or-DataTable-to-Word-Excel-PDF-and-CSV-Formats.aspx[^]


这篇关于将代码渲染为PDF格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆