Last post Aug 29, 2010 07:12 AM by CandorZ
Aug 28, 2010 07:57 AM|rockyy|LINK
yes i m using itextsharp.dll in my project
my requirement is i want to convert my whole page into a pdf format
the code which i have writtent is converting just the value which i m passing in my label's
see here e.g
protected void Page_Load(object sender, EventArgs e)
Label2.Text = "1";
Label3.Text = "Rockyy";
Label4.Text = "Sr.J.Cart";
protected void Button1_Click(object sender, EventArgs e)
var doc1 = new Document();
string path = Server.MapPath("pdf");
PdfWriter.GetInstance(doc1, new FileStream(path + "/doc1.pdf", FileMode.Create));
doc1.Add(new Paragraph(" my check"));
how i can just convert my whole page into a pdf that includes everything on page instead of just passing the whole value
any idea please ..
Aug 28, 2010 09:28 AM|kuujinbo|LINK
a couple of options:
 write a recursive method to iterate over everything in Page.Controls (static text is stored in LiteralControl objects), and pick the objects you want to write to PDF.
 get the .aspx page with
WebClient, then parse the HTML with iTextSharp
HTMLWorker. Or use one of the .NET XML parsers and pick the elements/nodes you want to write to PDF
http://kuujinbo.info/ | HTTP 301
Aug 28, 2010 10:22 AM|rockyy|LINK
can someone post a sample example? it will be an easy too understand how i could do that..
Aug 28, 2010 01:18 PM|Mikesdotnetting|LINK
The HtmlParser in iTextSharp is not very powerful. There is no easy way to replicate a web page using iTextSharp. I'd recommend spending some time generating a tempate PDF with some place holders for dynamic content which can be added at runtime. Invariably,
you do not want the whole page replicated in PDF format anyway (such as headers, footers, menus, adverts etc).
Aug 28, 2010 03:31 PM|CandorZ|LINK
You can use htmlparser.sourceforge.net/ and then somecode behind like
// step 1: creation of a document-object Document document = new Document(PageSize.A4, 80, 50, 30, 65); // step 2: // we create a writer that listens to the document // and directs a XML-stream to a file PdfWriter.getInstance(document, new FileStream("Chap0707.pdf", FileMode.Create)); // step 3: we parse the document HtmlParser.parse(document, "Chap0702.html");...http://www.ujihara.jp/iTextdotNET/en/examples.htmlSee Ya!
Aug 29, 2010 03:46 AM|rockyy|LINK
thanx Candorz for putting up a sample but it's saying HTML.parser doesn't exist in the current context
i have already included
well Mike that will be an issue if there are menu adverts etc on my page
but my page simply contains a peice of information in blocks of table
that it's a normal page which holds information with no menu's advert's etc.
and i want that page to be converted into pdf format
Aug 29, 2010 03:59 AM|Mikesdotnetting|LINK
OK, but you will find questions all over the Internet about using iTextSharp to convert an HTML page to PDF, and the answer is invariably the same: it's very difficult. That's because the HTML parser is not robust enough to handle anything other than valid
XML, and is not designed as an HTML parser in the sense you would like it to be. Even Bruno Lowagie (the creator of iText) in his book says it has not been designed for that. Some of the paid-for components can do what you want. Others work by firing up the
page in a Web browser type control and taking a screenshot. iTextSharp will not play nicely with css either. You will do so much work configuring styles etc within a document, that you may as well adopt the approach I suggested in the first place.
I'm just giving you the benefit of my experience with iTextsharp and the hundreds of questions I get emailed to me about using it to convert html to PDF as a result of the articles I've written on it. It's definitely what I would do.
Aug 29, 2010 07:12 AM|CandorZ|LINK
If you are only having some Text in the form of Tables than why dont you use Crystal Reports
Let me give you a demo
Add a CrystalReport.rpt from Add New Item into your Project
Now add a Dataset from Add New Item, adding this would really simplify your queries
Drag and drop the Table into the Dataset as shown in (1):
Now open the CrystalReport.rpt:
Into the Database fields ->Right Click->Database Expert->Current connections->Dataset->Select your Tables->Add them as shown in (2):
Drag and Drop Fields onto the Report from the Database Fields as shown in (3):
You can also add Text, Background, etc.
Prepare a Word Document and Import it as an OLE Object as shown in (4):
Thenafter you can drag and drop fields to appropriate places onto the word Document
Now to the Page that will display the Report, Add a New ASPX Page and to it, CrystalReport Viewer and CrystalReport Source, the form code will look something like:
Run the ASPX page, it will look like as in (5):