Yes the PDF will be getting generating inside a user control, but it needs to get the full page content. The html is not in the control its on the page that uses the control...
So for example index.aspx uses controlA.ascx and pdfgenerator.ascx is referenced in controlA.ascx...
So I need to somehow get to the content of the page...
please try below code, which will create web page as pdf.
I am using this code to create web page as pdf and it's working fine for me.
Dim bfTimes As BaseFont = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, False)
' Dim bscolor As BaseColor = BaseColor()
Dim font20 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.BOLD)
Dim font18 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD, New Color(255, 255, 255))
Dim font12 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 12, New Color(255, 255, 255))
Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Request.MapPath("~/images/logowhite.jpg"))
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=sample.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
' Dim mainFont As New Font(DIN, 20, Font.NORMAL)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
pnlPerson.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 35.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
Dim footer As New Paragraph("Your Footer comes here....", font12)
Dim pdffooter As New HeaderFooter(New Phrase(footer), True)
pdffooter.Alignment = Element.ALIGN_CENTER
pdffooter.Border = iTextSharp.text.Rectangle.NO_BORDER
pdffooter.BackgroundColor = New Color(200, 8, 190)
Dim Header As New Paragraph("Your Header comes here....", font18)
Dim pdfheader As New HeaderFooter(New Phrase(Header), True)
pdfheader.Alignment = Element.ALIGN_CENTER
pdfheader.Border = iTextSharp.text.Rectangle.NO_BORDER
pdfheader.BackgroundColor = New Color(200, 8, 190)
paritoshmmec
Participant
1555 Points
304 Posts
Re: PDF not opening as part of iTextSharp API
Mar 25, 2012 03:09 PM|LINK
quick question/clarification:
1. Just want to confirm PDF will be getting generated inside a usercontrol? right?
2. Where is your html or web page ? is it on same page or different page all together.
Please give us more info.
Thanks and Regards,
Paritosh
billy_111
Member
333 Points
878 Posts
Re: PDF not opening as part of iTextSharp API
Mar 25, 2012 03:38 PM|LINK
Hey,
Yes the PDF will be getting generating inside a user control, but it needs to get the full page content. The html is not in the control its on the page that uses the control...
So for example index.aspx uses controlA.ascx and pdfgenerator.ascx is referenced in controlA.ascx...
So I need to somehow get to the content of the page...
paritoshmmec
Participant
1555 Points
304 Posts
Re: PDF not opening as part of iTextSharp API
Mar 25, 2012 03:44 PM|LINK
Yes so get the innerhtml of control A pass it to pdfgenerator.ascx and generate it.
There Should be a property HTMLContent in Control A is needed and which shud be pass to of pdfgenerator.ascx.
Thanks and Regards,
Paritosh
sree1248
Member
4 Points
33 Posts
Re: PDF not opening as part of iTextSharp API
Feb 21, 2013 12:10 PM|LINK
Hie Billy,
please try below code, which will create web page as pdf.
I am using this code to create web page as pdf and it's working fine for me.
Dim bfTimes As BaseFont = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, False)
' Dim bscolor As BaseColor = BaseColor()
Dim font20 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.BOLD)
Dim font18 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD, New Color(255, 255, 255))
Dim font12 As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 12, New Color(255, 255, 255))
Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Request.MapPath("~/images/logowhite.jpg"))
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=sample.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
' Dim mainFont As New Font(DIN, 20, Font.NORMAL)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
pnlPerson.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 35.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
Dim footer As New Paragraph("Your Footer comes here....", font12)
Dim pdffooter As New HeaderFooter(New Phrase(footer), True)
pdffooter.Alignment = Element.ALIGN_CENTER
pdffooter.Border = iTextSharp.text.Rectangle.NO_BORDER
pdffooter.BackgroundColor = New Color(200, 8, 190)
'logo.Alignment = iTextSharp.text.Image.ALIGN_JUSTIFIED
logo.ScalePercent(50.0F)
logo.SetAbsolutePosition(500, 770)
Dim Header As New Paragraph("Your Header comes here....", font18)
Dim pdfheader As New HeaderFooter(New Phrase(Header), True)
pdfheader.Alignment = Element.ALIGN_CENTER
pdfheader.Border = iTextSharp.text.Rectangle.NO_BORDER
pdfheader.BackgroundColor = New Color(200, 8, 190)
pdfDoc.Header = pdfheader
pdfDoc.Footer = pdffooter
pdfDoc.Open()
pdfDoc.Add(logo)
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.[End]()