i found that..... you have to be make a paragraph object and add in paragraph object you have to be add chunk
but
before using pdfwriter you have to be add following namespace
using iTextSharp; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html;
and there i paste my code and you have to be use it and make it useful for you
protected void btnExport_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
form.Controls.Add(GridView1);
StringWriter sw = new StringWriter();
HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
form.Controls[0].RenderControl(hTextWriter);
string html = sw.ToString();
Document Doc = new Document();
//If u wanna save the pdf in application's root folder in server than use Request.PhysicalApplicationPath
//PdfWriter.GetInstance
//(Doc, new FileStream(Request.PhysicalApplicationPath
//+ "\\AmitJain.pdf", FileMode.Create));
//And if u wanna save the PDF at users Desktop than use Environment.GetFolderPath(Environment.SpecialFolder.Desktop
PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\Kamal.pdf", FileMode.Create));
Doc.Open();
//Now i m adding a paragraph to this document to be used asHeader by creating a new chuck and adding it to paragraph
Chunk c = new Chunk("Contact US \n",FontFactory.GetFont("Verdana", 15));
Paragraph p = new Paragraph();
p.Alignment = Element.ALIGN_CENTER;
p.Add(c);
Chunk chunk1 = new Chunk("By kamal, abc \n",FontFactory.GetFont("Verdana", 8));
Paragraph p1 = new Paragraph();
p1.Alignment = Element.ALIGN_RIGHT;
p1.Add(chunk1);
Chunk c2 = new Chunk("Conveted The Whole Gridview into pdf", FontFactory.GetFont("Verdana", 15));
Paragraph p2 = new Paragraph();
p2.Alignment = Element.ALIGN_CENTER;
p2.Add(c2);
Doc.Add(p);
Doc.Add(p1);
Doc.Add(p2);
//Now i m reading the html string created above through xmlTextReader and htmlParser to parse html elements
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(new StringReader(html));
HtmlParser.Parse(Doc, xmlReader);
Doc.Close();
string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\kamal.pdf";
ShowPdf(Path);
}
private void ShowPdf(string strS)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + strS);
Response.TransmitFile(strS);
Response.End();
//Response.WriteFile(strS);
Response.Flush();
Response.Clear();
}
Byteworm
Member
68 Points
21 Posts
Re: PDF
Aug 05, 2011 08:16 AM|LINK
Hello,
I used your code and the result is the same,
Compiler Error at position pdfwriter
thenks for your patience
kamalchhabra
Participant
1110 Points
272 Posts
Re: PDF
Aug 05, 2011 08:58 AM|LINK
you sent me the exact error
Copy of the error
i think the i can find
Byteworm
Member
68 Points
21 Posts
Re: PDF
Aug 05, 2011 09:08 AM|LINK
OK here it comes:
Compilerfehlermeldung: CS1002: ; erwartet.
Quellfehler:
Zeile 45: doc.Open(); Zeile 46: Zeile 47: /* Zeile 48: Chunk c1 = new Chunk(App.Firma); Zeile 49: Chunk c2 = new Chunk(App.Strasse);Quelldatei: c:\Users\Wolfgang\Documents\My Web Sites\Gregg Textil Site\Account\NewCustomer.cshtml Zeile: 47
dac.Open is the first code after your pdfwriter
kamalchhabra
Participant
1110 Points
272 Posts
Re: PDF
Aug 05, 2011 09:30 AM|LINK
Dear I can't Able To understand ur's language
but in your's code
i found that..... you have to be make a paragraph object and add in paragraph object you have to be add chunk
but
before using pdfwriter you have to be add following namespace
protected void btnExport_Click(object sender, EventArgs e) { HtmlForm form = new HtmlForm(); form.Controls.Add(GridView1); StringWriter sw = new StringWriter(); HtmlTextWriter hTextWriter = new HtmlTextWriter(sw); form.Controls[0].RenderControl(hTextWriter); string html = sw.ToString(); Document Doc = new Document(); //If u wanna save the pdf in application's root folder in server than use Request.PhysicalApplicationPath //PdfWriter.GetInstance //(Doc, new FileStream(Request.PhysicalApplicationPath //+ "\\AmitJain.pdf", FileMode.Create)); //And if u wanna save the PDF at users Desktop than use Environment.GetFolderPath(Environment.SpecialFolder.Desktop PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\Kamal.pdf", FileMode.Create)); Doc.Open(); //Now i m adding a paragraph to this document to be used asHeader by creating a new chuck and adding it to paragraph Chunk c = new Chunk("Contact US \n",FontFactory.GetFont("Verdana", 15)); Paragraph p = new Paragraph(); p.Alignment = Element.ALIGN_CENTER; p.Add(c); Chunk chunk1 = new Chunk("By kamal, abc \n",FontFactory.GetFont("Verdana", 8)); Paragraph p1 = new Paragraph(); p1.Alignment = Element.ALIGN_RIGHT; p1.Add(chunk1); Chunk c2 = new Chunk("Conveted The Whole Gridview into pdf", FontFactory.GetFont("Verdana", 15)); Paragraph p2 = new Paragraph(); p2.Alignment = Element.ALIGN_CENTER; p2.Add(c2); Doc.Add(p); Doc.Add(p1); Doc.Add(p2); //Now i m reading the html string created above through xmlTextReader and htmlParser to parse html elements System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(new StringReader(html)); HtmlParser.Parse(Doc, xmlReader); Doc.Close(); string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\kamal.pdf"; ShowPdf(Path); } private void ShowPdf(string strS) { Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=" + strS); Response.TransmitFile(strS); Response.End(); //Response.WriteFile(strS); Response.Flush(); Response.Clear(); }Byteworm
Member
68 Points
21 Posts
Re: PDF
Aug 05, 2011 09:40 AM|LINK
The paragraph and chunk ogjects are declared as comments /*
only the doc and the pdfwriter statements are activ
thanks
byteworm
kamalchhabra
Participant
1110 Points
272 Posts
Re: PDF
Aug 05, 2011 10:06 AM|LINK
no dear they are not commented
their color are change due to other reason you have to be aplied it got error then tell, if
not then mark it as a answer
Byteworm
Member
68 Points
21 Posts
Re: PDF
Aug 05, 2011 10:23 AM|LINK
Hello Kamal,
I reduced my code To:
@using iTextSharp; @using iTextSharp.text; @using iTextSharp.text.pdf; @using System.IO; @{ // Layoutseite und Seitentitel festlegen Layout = "~/_SiteLayout.cshtml"; Page.Title = "Neukundenantrag"; Document doc = new Document(); PdfWriter.GetInstance(doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\Neukundenantrag.pdf", FileMode.Create)); doc.Open(); } that' all and the same Errorkamalchhabra
Participant
1110 Points
272 Posts
Re: PDF
Aug 05, 2011 10:32 AM|LINK
are written these lines
HtmlForm form = new HtmlForm();
form.Controls.Add(GridView1);
StringWriter sw = new StringWriter();
HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
form.Controls[0].RenderControl(hTextWriter);
string html = sw.ToString();
Document Doc = new Document();
Byteworm
Member
68 Points
21 Posts
Re: PDF
Aug 05, 2011 10:44 AM|LINK
only the lines, I send before.
kamalchhabra
Participant
1110 Points
272 Posts
Re: PDF
Aug 05, 2011 10:55 AM|LINK
That's y?????
it show's error
You have to be wrotten these lines
because on there the gridview is converted into the html form and then stringwriter to html form and then string
form each word and then document make the new document for the pdf file so there you have to be specify
these lines