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
Subin Thomas
NA
4.9k
125.9k
how to add text in pdf programatically ?
Sep 26 2019 1:25 AM
i have writter a code to export pdf from a gridview and its working fine i had total 39 columns in gridview in that i needed few columns so i hided rest of the unwanted columns from the grid.
its exporting pdf but i wanted to add some text in that pdf but i dont knw how to below is my code.
i want to add some text as disclaimer fixed text.
public
void
exportPDFfile()
{
Response.ContentType =
"application/pdf"
;
Response.AddHeader(
"content-disposition"
,
"attachment;filename=ForwardingLetter.pdf"
);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw =
new
StringWriter();
HtmlTextWriter hw =
new
HtmlTextWriter(sw);
//hide the link button column
gridallemploye.Columns[0].Visible =
false
;
gridallemploye.Columns[2].Visible =
false
;
gridallemploye.Columns[3].Visible =
false
;
gridallemploye.Columns[4].Visible =
false
;
gridallemploye.Columns[5].Visible =
false
;
gridallemploye.Columns[6].Visible =
false
;
gridallemploye.Columns[7].Visible =
false
;
gridallemploye.Columns[8].Visible =
false
;
gridallemploye.Columns[9].Visible =
false
;
gridallemploye.Columns[11].Visible =
false
;
gridallemploye.Columns[12].Visible =
false
;
gridallemploye.Columns[13].Visible =
false
;
gridallemploye.Columns[14].Visible =
false
;
gridallemploye.Columns[15].Visible =
false
;
gridallemploye.Columns[16].Visible =
false
;
gridallemploye.Columns[17].Visible =
false
;
gridallemploye.Columns[18].Visible =
false
;
gridallemploye.Columns[19].Visible =
false
;
gridallemploye.Columns[20].Visible =
false
;
gridallemploye.Columns[21].Visible =
false
;
gridallemploye.Columns[22].Visible =
false
;
gridallemploye.Columns[23].Visible =
false
;
gridallemploye.Columns[24].Visible =
false
;
gridallemploye.Columns[25].Visible =
false
;
gridallemploye.Columns[26].Visible =
false
;
gridallemploye.Columns[27].Visible =
false
;
gridallemploye.Columns[28].Visible =
false
;
gridallemploye.Columns[29].Visible =
false
;
gridallemploye.Columns[30].Visible =
false
;
gridallemploye.Columns[31].Visible =
false
;
gridallemploye.Columns[32].Visible =
false
;
gridallemploye.Columns[33].Visible =
false
;
gridallemploye.Columns[34].Visible =
false
;
gridallemploye.Columns[38].Visible =
false
;
//Outputs server control content to a provided System.Web.UI.HtmlTextWriter
gridallemploye.RenderControl(hw);
//load the html content to the string reader
StringReader sr =
new
StringReader(sw.ToString());
//HTMLDocument
//Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Document document =
new
Document(PageSize.A4, 10f, 10f, 10f, 0f);
//iText class that allows you to convert HTML to PDF
HTMLWorker htmlWorker =
new
HTMLWorker(document);
//When this PdfWriter is added to a certain PdfDocument,
//the PDF representation of every Element added to this Document will be written to the outputstream.
PdfWriter.GetInstance(document, Response.OutputStream);
//open the document
document.Open();
htmlWorker.Parse(sr);
//close the document stream
document.Close();
//write the content to the response stream
Response.Write(document);
Response.End();
}
Reply
Answers (
2
)
Responsive UI in MVC
Datatable Sorting Not Working.