TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Khushboo Kumari
NA
112
14.6k
pdf generation and downloading at button click event
Nov 6 2017 3:08 AM
can you please help me to generate and download pdf document on buton click event
below code is giving error as path is not legal formate
protected
void
btnGenerateCertificate_Click(
object
sender, System.EventArgs e)
{
string
imageURL = Server.MapPath(
"../images/logo.png"
);
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
//Resize image depend upon your need
jpg.ScaleToFit(25f, 25f);
//Give space before image
//jpg.SpacingBefore = 1f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
//Header
Paragraph parag =
new
Paragraph(
"Road Construction Department"
,
new
iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE));
Paragraph paradate;
Paragraph subparag;
parag.SpacingAfter = 1f;
parag.Alignment = Element.ALIGN_CENTER;
subparag =
new
Paragraph(
"Govt. of Jharkhand"
,
new
iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
//subparag.SpacingAfter = 1f;
subparag.Alignment = Element.ALIGN_CENTER;
string
AppId = Session[
"ApplicantId"
].ToString();
string
datetime = DateTime.Now.ToString(
"dd-MMM-yyyy-H-mm-ss"
);
string
filename =
"Certificate_"
+ Session[
"ApplicantId"
].ToString() +
"_"
+ datetime +
".pdf"
;
FileStream file =
new
FileStream(Server.MapPath(
"~/Certificate/"
) + filename, FileMode.Create, System.IO.FileAccess.Write);
//save filename in database
string
param = AppId +
"~"
+ filename;
DataSet ds = BLobj.contractor_registration_Insert_Update_Certificate(connString, param);
StringWriter sw =
new
StringWriter();
HtmlTextWriter hw =
new
HtmlTextWriter(sw);
printableArea_IA_IB_IS.RenderControl(hw);
StringReader sr =
new
StringReader(sw.ToString());
Document pdfDoc =
new
Document(PageSize.A4, 10f, 10f, 100f, 0f);
PdfWriter.GetInstance(pdfDoc, file);
pdfDoc.Open();
pdfDoc.Add(jpg);
pdfDoc.Add(parag);
pdfDoc.Add(subparag);
HTMLWorker htmlparser =
new
HTMLWorker(pdfDoc);
MemoryStream ms =
new
MemoryStream();
htmlparser.Parse(sr);
pdfDoc.Close();
file.Close();
Response.Redirect(
"Summary_Application1.aspx"
);
}
Reply
Answers (
1
)
Send SMS from GSM Modem
how to filter items from a selected dropdown list