当用户点击打印/问题时,它会生成pdf文件;我希望用户在不同的选项卡中打开pdf文件,以及当前选项卡重定向到主页;因为我已经有了回报;我不确定如何同时重定向到主页。这就是我迄今为止的目标
<table>
<tr>
<th class="col-md-4">Item Number</th>
<th class="col-md-4">Item Description</th>
<th class="col-md-4">Expense Account</th>
<th class="col-md-2">Quantity Requested</th>
<th class="col-md-2">Quantity Issued</th>
<th class="col-md-1">UOM</th>
<th class="col-md-1">Item Price</th>
</tr>
@{
if (@Model.items.Count > 0)
{
foreach (var issueditem in @Model.items)
{
<tr>
<td class="col-md-4">@issueditem.itemNumber</td>
<td class="col-md-4">@issueditem.description</td>
<td class="col-md-4">@issueditem.expense_account.getDescription</td>
<td class="col-md-2">@issueditem.quantity.ToString()</td>
<td class="col-md-2">@issueditem.quantityI.ToString()</td>
<td class="col-md-1">@issueditem.selecteduomtext </td>
<td class="col-md-1">@issueditem.price.ToString()</td>
<td> @Html.ActionLink("Edit", "Edit", new { id = issueditem.lineNum }) </td>
</tr>
}
}
}
</table>
<button type="submit" class="btn btn-default" formaction="@Url.Action("ReceiptPrint")">Print/Issue</button>
控制器
public ActionResult ReceiptPrint(Issue issue)
{
IssueDAO dbdata = new IssueDAO();
dbdata.connectionString = ConfigurationManager.ConnectionStrings
["TConnectionString"].ConnectionString;
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("Index", 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"));
return File(bytes, "application/pdf");
}