现在,我有一个带有html.actionLink的index.cshtml,它带有一个html表的预览,该html表将数据从表单中拉出以准备打印它。然后,当我单击链接时,它将转到带有HTML的PDFOnePage.cshtml的预览。然后有一个按钮可以将其转到abcpdf方法进行打印。我想将两种动作都从index.cshtml转移到一个步骤。
这是我的index.cshtml的一部分,带有链接:
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("PDF", "PDFOnePage", new { id = item.ID })
</td>
然后,当我单击PDF链接时,它会在打印之前显示html。
PDFOnePage.cshtml看起来像这样:
<table frame="box" style="width:100%; border-collapse:separate">
<tr>
<td colspan="3"> <b>BlahBlahBlahLotsOfStuff</b></td>
</tr>
</table>
<button>
<a href="@Url.Action("HmtltoPDF2","Applicant")">Export PDF</a>
</button>
因此,当我们单击该按钮时,它将显示PDF,而当我执行ctrl-p时,它将显示打印gui。
该按钮访问我的ApplicantController.cs方法:
public FileStreamResult HmtltoPDF2()
{
//getting the url to convert to pdf
String PreviousPage = System.Web.HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
//abcpdf was annoying for not accepting the Url directly
//so just make a string variable to assign the value of the url
// DO NOT delete this and use PreviousPage directly
//it will break the PDF Convertion.
String HtmlToPDFConvertion = PreviousPage;
MemoryStream m = new MemoryStream();
Doc theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.FontSize = 8;
//theDoc.Rect.Inset(114, 162);
theDoc.Rect.Inset(15, 1);
theDoc.HtmlOptions.Engine = EngineType.Chrome;
theDoc.HtmlOptions.UseScript = true; // enable JavaScript
theDoc.HtmlOptions.Media = MediaType.Print; // Or Screen for a more screen oriented output
theDoc.HtmlOptions.InitialWidth = 800; // In case we have a responsive site which is non-specific on good widths
//theDoc.HtmlOptions.RepaintDelay = 500; // Only required if you have AJAX or animated content such as graphs
//theDoc.HtmlOptions.IgnoreCertificateErrors = false; // Disabled for ease of debugging
//theDoc.HtmlOptions.FireShield.Policy = XHtmlFireShield.Enforcement.Deny; // Disabled for ease of debugging
theDoc.Page = theDoc.AddPage();
int theID;
theID = theDoc.AddImageUrl(HtmlToPDFConvertion);
while (true)
{
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc.Save(Server.MapPath(Path));
byte[] theData = theDoc.GetData();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
Response.End();
return File(m, "application/pdf", "test.pdf");
//theDoc.Clear();
}
这都是步骤的示意图:
如何摆脱在打印前两次查看PDF / html的中间步骤?就像将html.actionLink(PDF)和href Url.Action htmltoPDF2放在一起一样?我不想打印带有页面内容或滚动条的按钮。
我在这类事情上没有很多经验,因此我不确定要用谷歌搜索如何将它们整合到一个步骤中。我从一个不在这里的人那里继承了此网页。