what's the problem? Is the provided tutorial not working? 7070 (included below) converts chap0702 to a pdf document?
Console.WriteLine("Chapter 7 example 7: parsing the HTML from example 2");
// 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");
Ok? I guess if any other dumbasses are out there, please make sure you have the following at the top:
using iTextSharp.text;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
Seems I forgot the HTML one which is why I could not see HtmlParser, but I found this on my one although I swore I had it. Ugh, always double check your declarations so I hope this helps other idiots like me... :)
ORIGINAL POST:
I think what he wants to say is that this does not work because HtmlParser does not seem to be part of iTextSharp. I keep seeing various examples floating around online about converting HTML to PDF but they allO reference HtmlParser which does NOT seem to
exist within iTextSharp so where is this coming from? Do we have to install something else? Let me know, thanks...
To clarify before people start to say that HtmlParser is within iTextSharp... I am using the .NET version from
http://sourceforge.net/projects/itextsharp/ so this is NOT THE JAVA version but the .NET VERSION and it does not seem to have HtmlParser, so can someone explain to me if I am doing something wrong?
I got itextsharp version 4.1.6.0 and got it to work like this
for parsing html not in a file...:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Collections;
using System.Text;
using iTextSharp.text.xml;
using iTextSharp.text.html;
public partial class itexttest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create document
Document document = new Document();
try {
//writer - have our own path!!! and see you have write permissions...
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/") + "WordDoc/" + "parsetest.pdf", FileMode.Create));
document.Open();
//html -text - kan be from database or editor too
String htmlText="<font " +
" color=\"#0000FF\"><b><i>Title One</i></b></font><font " +
" color=\"black\"><br><br>Some text here<br><br><br><font " +
" color=\"#0000FF\"><b><i>Another title here " +
" </i></b></font><font " +
" color=\"black\"><br><br>Text1<br>Text2<br><OL><LI>hi</LI><LI>how are u</LI></OL>";
//make an arraylist ....with STRINGREADER since its no IO reading file...
ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);
//add the collection to the document
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
document.Add(new Paragraph("And the same with indentation...."));
// or add the collection to an paragraph
// if you add it to an existing non emtpy paragraph it will insert it from
//the point youwrite -
Paragraph mypara = new Paragraph();//make an emtphy paragraph as "holder"
mypara.IndentationLeft = 36;
mypara.InsertRange(0, htmlarraylist);
document.Add(mypara);
document.Close();
I am getting this error at ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList (new StringReader(htmlText), null); Cannot implicitly convert type 'system.collection,generic.list to system.collections.arraylist
Shailen
Member
89 Points
81 Posts
Convert html to pdf using iTextSharp
Jan 01, 2008 03:37 PM|LINK
can anyone provide me a sample code who have used iTextsharp(chapter 0707) to convert HTML to PDF.... Please help.... urgent...!!!
Shailen
Visit My Blog
Rinze
Contributor
2580 Points
480 Posts
Re: Convert html to pdf using iTextSharp
Jan 02, 2008 07:52 AM|LINK
what's the problem? Is the provided tutorial not working? 7070 (included below) converts chap0702 to a pdf document?
Console.WriteLine("Chapter 7 example 7: parsing the HTML from example 2");
// 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");
you can find a different set of tutorials here
Rinze Cats
---------
please select 'mark as answer' if this post helped you!
Shailen
Member
89 Points
81 Posts
Re: Convert html to pdf using iTextSharp
Jan 03, 2008 06:28 PM|LINK
No, its not working.... i tried it.... but still it didn't work....Shailen
Visit My Blog
Rinze
Contributor
2580 Points
480 Posts
Re: Convert html to pdf using iTextSharp
Jan 03, 2008 06:48 PM|LINK
Sorry, you marked it is answered... does your problem still exist?
can you tell me in more detail what the problem is?
Rinze Cats
---------
please select 'mark as answer' if this post helped you!
DonChino
Member
2 Points
1 Post
Re: Convert html to pdf using iTextSharp
May 05, 2008 06:05 PM|LINK
Ok? I guess if any other dumbasses are out there, please make sure you have the following at the top:
using iTextSharp.text;
using iTextSharp.text.html;
using iTextSharp.text.pdf;
Seems I forgot the HTML one which is why I could not see HtmlParser, but I found this on my one although I swore I had it. Ugh, always double check your declarations so I hope this helps other idiots like me... :)
ORIGINAL POST:
I think what he wants to say is that this does not work because HtmlParser does not seem to be part of iTextSharp. I keep seeing various examples floating around online about converting HTML to PDF but they allO reference HtmlParser which does NOT seem to exist within iTextSharp so where is this coming from? Do we have to install something else? Let me know, thanks...
To clarify before people start to say that HtmlParser is within iTextSharp... I am using the .NET version from http://sourceforge.net/projects/itextsharp/ so this is NOT THE JAVA version but the .NET VERSION and it does not seem to have HtmlParser, so can someone explain to me if I am doing something wrong?
starazam
Member
27 Points
20 Posts
Re: Convert html to pdf using iTextSharp
Jan 28, 2010 05:30 AM|LINK
I were having same, but then I found, in new version we need to use HTMLWorker.ParseToList() instead of HtmlParser......
Software Engineer,
Virtual Works, Lahore, Pakistan
.netdevelop
Member
20 Points
10 Posts
Re: Convert html to pdf using iTextSharp
Apr 29, 2010 12:15 PM|LINK
I got itextsharp version 4.1.6.0 and got it to work like this
for parsing html not in a file...:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Collections;
using System.Text;
using iTextSharp.text.xml;
using iTextSharp.text.html;
public partial class itexttest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create document
Document document = new Document();
try {
//writer - have our own path!!! and see you have write permissions...
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/") + "WordDoc/" + "parsetest.pdf", FileMode.Create));
document.Open();
//html -text - kan be from database or editor too
String htmlText="<font " +
" color=\"#0000FF\"><b><i>Title One</i></b></font><font " +
" color=\"black\"><br><br>Some text here<br><br><br><font " +
" color=\"#0000FF\"><b><i>Another title here " +
" </i></b></font><font " +
" color=\"black\"><br><br>Text1<br>Text2<br><OL><LI>hi</LI><LI>how are u</LI></OL>";
//make an arraylist ....with STRINGREADER since its no IO reading file...
ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);
//add the collection to the document
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
document.Add(new Paragraph("And the same with indentation...."));
// or add the collection to an paragraph
// if you add it to an existing non emtpy paragraph it will insert it from
//the point youwrite -
Paragraph mypara = new Paragraph();//make an emtphy paragraph as "holder"
mypara.IndentationLeft = 36;
mypara.InsertRange(0, htmlarraylist);
document.Add(mypara);
document.Close();
}
catch (Exception exx) {
Console.Error.WriteLine(exx.StackTrace);
Console.Error.WriteLine(exx.Message);
}
}
}
good luck....
.netdevelop
Member
20 Points
10 Posts
Re: Convert html to pdf using iTextSharp
Apr 29, 2010 12:26 PM|LINK
just for info
i used null as argument for stylesheet - but you kan add one of course if you want to...
i use an editor and all the formatting is done to the db as html...
bhupendra TG
Member
28 Points
21 Posts
Re: Convert html to pdf using iTextSharp
May 10, 2010 03:37 PM|LINK
I am getting this error at ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList (new StringReader(htmlText), null); Cannot implicitly convert type 'system.collection,generic.list to system.collections.arraylist
.netdevelop
Member
20 Points
10 Posts
Re: Convert html to pdf using iTextSharp
May 27, 2010 10:41 PM|LINK
What version of DLL are you using. Practically you should be able to cast it by converting it to arraylist
if you send me the codesnippet you have and the dll version i will try to help you out
Cannot implicitly convert type 'system.collection,generic.list to system.collections.arraylist -->
that means you cant convert it to arraylist? - did you try?
ArrayList htmlarraylist = (ArrayList)iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);