如何使用asp.net在pdf文档中弹出最终用户提交的注册详细信息? [英] how do I pop up end user submitted registration details in pdf document using asp.net?
本文介绍了如何使用asp.net在pdf文档中弹出最终用户提交的注册详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将注册详细信息存储到数据库&存储后,我想在pdf文档中显示相同的详细信息,以便最终用户可以下载或打印它。 pdf应该弹出或在新的浏览器窗口中打开..
生成pdf的代码如下:
I want to store the Registration details into database & after storing, I want to display same details in pdf document so that the end user can download or take a print of it. the pdf should be open as a pop up or in new browser window..
Code for generating pdf is as follows:
protected void GenerateReport(object sender, EventArgs e)
{
MemberInfoSelected objSelectedMember = new MemberInfoSelected();
objSelectedMember.UserName = email.Text.Trim();
SqlDataReader dr = objSelectedMember.UserNameSelect(out ErrorMessage);
dr.Read();
Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
PdfTemplate template = new PdfTemplate();
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
Color color = null;
document.Open();
//Header Table
table = new PdfPTable(2);
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.3f, 0.7f });
//Company Logo
cell = ImageCell("~/images/title_tag.gif", 30f, PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
table.AddCell(cell);
document.Add(table);
table = new PdfPTable(2);
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.3f, 0.7f });
cell = ImageCell("~/images/dhwajLogo.gif", 30f, PdfPCell.ALIGN_LEFT);
table.AddCell(cell);
cell = ImageCell("~/images/Name_New.gif", 40f, PdfPCell.ALIGN_JUSTIFIED);
cell.Colspan = 2;
table.AddCell(cell);
document.Add(table);
table = new PdfPTable(2);
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.3f, 0.7f });
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.VerticalAlignment = PdfCell.ALIGN_TOP;
cell.Colspan = 2;
table.AddCell(cell);
document.Add(table);
//Separater Line
color = new Color(System.Drawing.ColorTranslator.FromHtml("#da251c"));
DrawLine(writer, 25f, document.Top - 130f, document.PageSize.Width - 25f, document.Top - 130f, color);
table = new PdfPTable(2);
table.HorizontalAlignment = Element.ALIGN_LEFT;
table.SetWidths(new float[] { 0.3f, 1f });
table.SpacingBefore = 30f;
cell = PhraseCell(new Phrase("Registration Form", FontFactory.GetFont("Arial",12,Font.UNDERLINE,Color.BLACK)), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
table.AddCell(cell);
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 30f;
table.AddCell(cell);
DrawRectAngle(writer, color);
//Name
phrase = new Phrase();
phrase.Add(new Chunk("NAME -: " + dr["FirstName"] + " " + dr["MiddleName"] + " " + dr["LastName"] + "\n", FontFactory.GetFont("Arial", 10, Font.BOLD, Color.BLACK)));
phrase.Add(new Chunk("NAME (in Marathi) -: " + dr["MarathiFirstName"] + " " + dr["MarathiMiddleName"] + " " + dr["MarathiLastName"] + "\n", FontFactory.GetFont("Mangal",10, Font.BOLD, Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.Colspan = 2;
cell.VerticalAlignment = PdfPCell.ALIGN_LEFT;
table.AddCell(cell);
document.Add(table);
table = new PdfPTable(2);
table.SetWidths(new float[] { 0.5f, 2f });
table.TotalWidth = 340f;
table.LockedWidth = true;
table.SpacingBefore = 20f;
table.HorizontalAlignment = Element.ALIGN_RIGHT;
//Date of Birth
table.AddCell(PhraseCell(new Phrase("Date of Birth:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(Convert.ToDateTime(dr["DateOfBirth"]).ToString("dd MMMM, yyyy")+"\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Gender
table.AddCell(PhraseCell(new Phrase("Gender:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
if (dr["Male"].Equals(true))
table.AddCell(PhraseCell(new Phrase("Male \n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
else
table.AddCell(PhraseCell(new Phrase("Female \n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Marital Status
table.AddCell(PhraseCell(new Phrase("Marital Status:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(dr["MaritalStatus"]+"\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Education
table.AddCell(PhraseCell(new Phrase("Education:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(dr["Education"]+"\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Occupation
table.AddCell(PhraseCell(new Phrase("Occupation:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(dr["Occupation"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Email
table.AddCell(PhraseCell(new Phrase("Email:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
table.AddCell(PhraseCell(new Phrase(dr["Email"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
//Address
table.AddCell(PhraseCell(new Phrase("Address:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
phrase = new Phrase(new Chunk(dr["Address"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
table.AddCell(PhraseCell(phrase, PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
document.Add(table);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType= "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + dr["FirstName"] + " " + dr["LastName"] + "-Registration Form.pdf");
Response.ContentType= "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
}
推荐答案
嗨..请查看以下文章:
http://weblog.west-wind.com/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET [ 在浏览器1上查看
http://www.evagoras.com/2011/02/08/downloading-any-file-to -the-browser-part-ii-using-asp-net / [在浏览器2上查看
Hi.. Please look into the following articles:
http://weblog.west-wind.com/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET[View on Browser 1]
http://www.evagoras.com/2011/02/08/downloading-any-file-to-the-browser-part-ii-using-asp-net/[View on Browser 2]
这篇关于如何使用asp.net在pdf文档中弹出最终用户提交的注册详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文