【发布时间】:2017-10-18 13:56:20
【问题描述】:
当我尝试生成 pdf 时;我得到了 pdf,但输入的数据没有显示在 pdf 文件中,而相同的信息被发送到数据库。我看到了该信息,但我不确定与 pdf 文件有关的问题可能是什么。而且我在不同的浏览器上都试过了,还是一样的。
更新
IssueDAO dbdata = new IssueDAO();
dbdata.connectionString = ConfigurationManager.ConnectionStrings["TWCL_OPERATIONSConnectionString"].ConnectionString;
getIssue.transactionDate = DateTime.Now; //Sets the transaction date to current date
getIssue.status = -1;
Item item = new Item();
try
{
dbdata.createIssue(getIssue, item);//Creates the issue in the database
}
catch (Exception ex)
{
LogWrite logWriter = new LogWrite(ex.ToString());
ViewBag.errorMessage = "Unable to complete the Issue. Please see Log file for more Information";
return View("IssueItem", getIssue);
}
DataSet ds = dbdata.GetReceipt(getIssue.requisitionNumber);
LocalReport localreport = new LocalReport();
localreport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Reciept.rdlc";
localreport.DataSources.Add(new ReportDataSource("Receipt_Data", ds.Tables[0]));
localreport.SetParameters(new ReportParameter("Req_num", getIssue.requisitionNumber));
string reporttype = "PDF";
string mimeType;
string encoding;
string fileNameExtension = "pdf";
string deviceInfo = @"<DeviceInfo>
<OutputFormat>PDF</OutputFormat>
<PageWidth>8.5in</PageWidth>
<PageHeight>11in</PageHeight>
<MarginTop>0.25in</MarginTop>
<MarginLeft>0.45in</MarginLeft>
<MarginRight>0.45in</MarginRight>
<MarginBottom>0.25in</MarginBottom></DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localreport.Render(
reporttype, deviceInfo, out mimeType, out encoding, out fileNameExtension,
out streams, out warnings);
var doc = new iTextSharp.text.Document();
var reader = new PdfReader(renderedBytes);
using (FileStream fs = new FileStream(Server.MapPath("~/Receipt" +
Convert.ToString(Session["CurrentUserName"]) + ".pdf"), FileMode.Create))
{
PdfStamper stamper = new PdfStamper(reader, fs);
string Printer = "Xerox Phaser 3635MFP PCL6";
// This is the script for automatically printing the pdf in acrobat viewer
stamper.JavaScript = "var pp = getPrintParams();pp.interactive =pp.constants.interactionLevel.automatic; pp.printerName = " +
Printer + ";print(pp);\r";
stamper.Close();
}
reader.Close();
FileStream fss = new FileStream(Server.MapPath("~/Receipt.pdf"), FileMode.Open);
byte[] bytes = new byte[fss.Length];
fss.Read(bytes, 0, Convert.ToInt32(fss.Length));
fss.Close();
System.IO.File.Delete(Server.MapPath("~/Receipt.pdf"));
//Here we returns the file result for view(PDF)
ModelState.Clear();
Session.Clear(); //Clears the session variable for reuse
return File(bytes, "application/pdf");
}
【问题讨论】:
-
你调试代码了吗?你检查
ds.Tables[0]里面有没有数据? -
是的,它确实有数据。
-
我已经停止使用 c# 来生成 excel 和 PDF ...客户端上的 JS 足以生成易于操作的文档..只需以某种方式将数据发送到客户端......然后做事跨度>
-
@Rohitas 最好举一些例子来说明在客户端使用什么来做到这一点。
-
@FarrukhSubhani 是的 :)
标签: c# asp.net asp.net-mvc pdf