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
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Create PDF File in ASP.NET
Kumar Bhimsen
Dec 25
2015
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
itextsharpdll.zip
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.IO;
using
iTextSharp.text;
using
iTextSharp.text.pdf;
public
partial
class
_Default: Page {
protected
void
Page_Load(
object
sender, EventArgs e) {}
protected
void
GenerateReport_Click(
object
sender, EventArgs e) {
var doc =
new
Document(PageSize.A4);
// defining the docment
var output =
new
MemoryStream();
var wri = PdfWriter.GetInstance(doc, output);
var fpara =
new
Phrase(
"\n"
);
fpara.Add(
" * * * * * * You are Welcome * * * * * * "
);
fpara.Add(
" \n"
);
fpara.Add(
" \n"
);
string
url =
"~/Image/kbs.jpg"
;
var headerImage = iTextSharp.text.Image.GetInstance(
new
Uri(Server.MapPath(url)));
/// Adding border to image if required
headerImage.Border = iTextSharp.text.Rectangle.BOX;
headerImage.BorderColor = iTextSharp.text.Color.BLACK;
headerImage.BorderWidth = 3 f;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
doc.Open();
Rectangle defaultPageSize = PageSize.A4;
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252,
false
);
Font fontH1 =
new
Font(bfTimes, 9, Font.NORMAL, Color.BLUE);
PdfPTable table =
new
PdfPTable(1);
// You can change the number of columns as per required in our case i think we need only one column
List <
string
> paras =
new
List <
string
> ();
foreach
(
string
p1
in
paras) {
PdfPCell cell =
new
PdfPCell(
new
Phrase(p1, fontH1));
//cell.FixedHeight = 15f;
table.AddCell(cell);
}
doc.Add(headerImage);
/// added header image
fpara.Add(
"visit us : kumarbhimsenbgp.blogspot.in"
);
fpara.Add(
"\n"
);
doc.Add(fpara);
/// added 1
doc.Add(table);
/// added table
doc.NewPage();
/// aad a new Page when doc item exceed.
doc.Close();
//Close document
Response.ContentType =
"application/pdf"
;
Response.AddHeader(
"content-disposition"
,
"attachment;filename=KbsTest.pdf"
);
Response.BinaryWrite(output.ToArray());
}
}
create pdf in c#