Discussion:
[itextsharp-questions] Assigning HTML string to a PDFCell
sunilshishodia
2006-11-03 07:04:32 UTC
Permalink
I am trying to assign a HTML string that I am fetching from database to a
pdfcell. I checked previous posts pertaining to questions like this and
found HTMLWorker class to parse HTML string like this

ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);

My problem is that I am fetching HTML string from database and contains
formatting. Is there any way I can assign html string directly to pdf cell
without having to use stringreader and stylesheet. I need to show HTML
string with same formatting in PDF generated.
If there is no way out without using stringreader and style , how
can i assign and put it into my pdf document.

my code is :
Dim document As Document = New Document
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1
Dim cell As Cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim img0 As Image =
Image.GetInstance("C:\DefaultNewsLetterImgae.jpg")
img0.Alignment = Image.MIDDLE_ALIGN
cell.Add(img0)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 2
Dim helvetica As BaseFont = BaseFont.CreateFont("Helvetica",
BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim font1 As Font = New Font(helvetica, 8, Font.NORMAL)
Dim chk As Chunk = New Chunk(" " )// Would like to show my HTML
string here
cell.Add(chk)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
helvetica = BaseFont.CreateFont("Helvetica", BaseFont.CP1252,
BaseFont.NOT_EMBEDDED)
font1 = New Font(helvetica, 8, Font.NORMAL)
chk = New Chunk("Volume Number XVII", font1)
cell.Add(chk)
table.AddCell(cell)

document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()
Regards
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566334.html#a7152766
Sent from the itextsharp-questions mailing list archive at Nabble.com.
sunilshishodia
2006-11-03 07:05:26 UTC
Permalink
I am trying to assign a HTML string that I am fetching from database to a
pdfcell. I checked previous posts pertaining to questions like this and
found HTMLWorker class to parse HTML string like this

ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);

My problem is that I am fetching HTML string from database and contains
formatting. Is there any way I can assign html string directly to pdf cell
without having to use stringreader and stylesheet. I need to show HTML
string with same formatting in PDF generated.
If there is no way out without using stringreader and style , how
can i assign and put it into my pdf document.

my code is :
Dim document As Document = New Document
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1
Dim cell As Cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim img0 As Image =
Image.GetInstance("C:\DefaultNewsLetterImgae.jpg")
img0.Alignment = Image.MIDDLE_ALIGN
cell.Add(img0)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 2
Dim helvetica As BaseFont = BaseFont.CreateFont("Helvetica",
BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim font1 As Font = New Font(helvetica, 8, Font.NORMAL)
Dim chk As Chunk = New Chunk(" " )// Would like to show my HTML
string here
cell.Add(chk)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
helvetica = BaseFont.CreateFont("Helvetica", BaseFont.CP1252,
BaseFont.NOT_EMBEDDED)
font1 = New Font(helvetica, 8, Font.NORMAL)
chk = New Chunk("Volume Number XVII", font1)
cell.Add(chk)
table.AddCell(cell)

document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()
Regards
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7152773
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Paulo Soares
2006-11-03 14:36:39 UTC
Permalink
I looks like you already provided the solution.

Paulo
-----Original Message-----
On Behalf Of sunilshishodia
Sent: Friday, November 03, 2006 7:05 AM
Subject: [itextsharp-questions] Assigning HTML string to a PDFCell
I am trying to assign a HTML string that I am fetching from
database to a
pdfcell. I checked previous posts pertaining to questions
like this and
found HTMLWorker class to parse HTML string like this
ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
My problem is that I am fetching HTML string from database
and contains
formatting. Is there any way I can assign html string
directly to pdf cell
without having to use stringreader and stylesheet. I need to show HTML
string with same formatting in PDF generated.
If there is no way out without using stringreader
and style , how
can i assign and put it into my pdf document.
Dim document As Document = New Document
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1
Dim cell As Cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim img0 As Image =
Image.GetInstance("C:\DefaultNewsLetterImgae.jpg")
img0.Alignment = Image.MIDDLE_ALIGN
cell.Add(img0)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 2
Dim helvetica As BaseFont =
BaseFont.CreateFont("Helvetica",
BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
Dim font1 As Font = New Font(helvetica, 8, Font.NORMAL)
Dim chk As Chunk = New Chunk(" " )// Would like
to show my HTML
string here
cell.Add(chk)
table.AddCell(cell)
cell = New Cell
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
helvetica = BaseFont.CreateFont("Helvetica",
BaseFont.CP1252,
BaseFont.NOT_EMBEDDED)
font1 = New Font(helvetica, 8, Font.NORMAL)
chk = New Chunk("Volume Number XVII", font1)
cell.Add(chk)
table.AddCell(cell)
document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()
Regards
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf256
6338.html#a7152773
Sent from the itextsharp-questions mailing list archive at Nabble.com.
--------------------------------------------------------------
-----------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to make
your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Aviso Legal:
Esta mensagem � destinada exclusivamente ao destinat�rio. Pode conter informa��o confidencial ou legalmente protegida. A incorrecta transmiss�o desta mensagem n�o significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. � proibido a qualquer pessoa que n�o o destinat�rio de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.
sunilshishodia
2006-11-06 05:24:50 UTC
Permalink
Hi,
I am sorry but i believe you could not get my problem. The code

ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);

will add parsed html string to pdfcell. But, I have a HTML string coming
from database and want to assign it to pdfcell. I wanted to know whether
HTML can be directly assigned to pdfcell without using String reader and
style. I want to preserve the style embedded in HTML string , so , do not
want to make new style sheet to be passed to HTMLWorker.ParseToList. Is
there any way out for this?

Regards
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7193513
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Paulo Soares
2006-11-06 09:23:48 UTC
Permalink
I really can't get your problem. Your code can take a String, assign it to
StringReader, use or not use a style and create a PdfPCell. So, you have an
HTML String and get a PdfPCell with the parsed HTML inside. HTMLWorker won't
parse CSS if that's what you're asking.

Paulo

----- Original Message -----
From: "sunilshishodia" <***@emessages.com>
To: <itextsharp-***@lists.sourceforge.net>
Sent: Monday, November 06, 2006 5:24 AM
Subject: Re: [itextsharp-questions] Assigning HTML string to a PDFCell
Post by sunilshishodia
Hi,
I am sorry but i believe you could not get my problem. The code
ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
will add parsed html string to pdfcell. But, I have a HTML string coming
from database and want to assign it to pdfcell. I wanted to know whether
HTML can be directly assigned to pdfcell without using String reader and
style. I want to preserve the style embedded in HTML string , so , do not
want to make new style sheet to be passed to HTMLWorker.ParseToList. Is
there any way out for this?
Regards
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7193513
Sent from the itextsharp-questions mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
sunilshishodia
2006-11-06 09:44:51 UTC
Permalink
Hi,
I am able to assign parsed html string to pdf cell but what I am getting
is mingled string on pdf.I am attaching resultant pdf of the code that I am
using to generate pdf.Code is as follows.


Dim document As Document = New Document(PageSize.A4, 80, 50, 30, 65)
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1

Dim cell As Cell

cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
table.AddCell(cell)
cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim strHtml As String = "<SPAN style='FONT-SIZE: 16pt;
FONT-FAMILY: 'Times New Roman'><STRONG><U><FONT color=#000080>Happy 2006 to
our EMS Family and Friends!</FONT></U><BR><BR></STRONG></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>I hope 2005 was as good to you,
your families and your work life as it was for us here at Education
Management Solutions.<BR><BR>During 2005, EMS improved its product line,
expanded its audience, entered several new markets, and added the personnel
needed to continue our robust growth through 2006.<BR><BR>While delighted
with our progress and rosy future, we always remember that we cannot go
forward <BR>without you, our customers. Everything that EMS produces,
introduces, creates and implements all centers around what will best serve
the needs of our clients and our market. <BR></SPAN></FONT><SPAN
style='FONT-SIZE: 11pt; FONT-FAMILY: 'Times New Roman'><BR></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>Throughout 2006, we will
continue to strive for customer delight, not just customer satisfaction.
We’ll be both proactive (creating solutions to better serve you in the
future) and reactive (handling your questions and requests).&nbsp; We’ll
work hard to make sure you’re happy with your EMS
solution.<BR></SPAN></FONT>"
Dim bytes As Byte() =
System.Text.Encoding.ASCII.GetBytes(strHtml)
Dim style As StyleSheet = New StyleSheet

Try
Dim srReader As New StreamReader(New MemoryStream(bytes),
System.Text.Encoding.Default)
Dim alist As ArrayList
alist = HTMLWorker.ParseToList(srReader, style)
Dim alElement As IElement
For Each alElement In alist
cell.AddElement(alElement)
Next

Catch ex As Exception

End Try
table.AddCell(cell)
document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()

Also, does the height of the pdfcell that I am assigning HTML , adjusts
automatically to the content i.e. increases if content increases.What
mistake I am making in code that is displaying mingled string in pdf
Regards
Post by Paulo Soares
I really can't get your problem. Your code can take a String, assign it to
StringReader, use or not use a style and create a PdfPCell. So, you have an
HTML String and get a PdfPCell with the parsed HTML inside. HTMLWorker won't
parse CSS if that's what you're asking.
Paulo
----- Original Message -----
Sent: Monday, November 06, 2006 5:24 AM
Subject: Re: [itextsharp-questions] Assigning HTML string to a PDFCell
Post by sunilshishodia
Hi,
I am sorry but i believe you could not get my problem. The code
ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
will add parsed html string to pdfcell. But, I have a HTML string coming
from database and want to assign it to pdfcell. I wanted to know whether
HTML can be directly assigned to pdfcell without using String reader and
style. I want to preserve the style embedded in HTML string , so , do not
want to make new style sheet to be passed to HTMLWorker.ParseToList. Is
there any way out for this?
Regards
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7193513
Sent from the itextsharp-questions mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7195850
Sent from the itextsharp-questions mailing list archive at Nabble.com.
shailen
2008-01-02 00:16:14 UTC
Permalink
Sushil, this is shailendra...

I am working on a application where i have to convert online html code to
pdf... and i tried your code and also seen your conversion...

SO can you please let me know if you have solved that problem... Please help
yaar... its very urgent...
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tp7152773p14571425.html
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Paulo Soares
2006-11-06 11:24:23 UTC
Permalink
Your PDF didn't show up. The following code in C# produces the attached
PDF.

FontFactory.RegisterDirectories();
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new
FileStream(@"C:\test.pdf", FileMode.Create));
document.Open();
PdfPTable t = new PdfPTable(1);
String ss = "<SPAN style='FONT-SIZE: 16pt;FONT-FAMILY: Times New
Roman'><STRONG><U><FONT color=#000080>Happy 2006 to our EMS Family and
Friends!</FONT></U><BR><BR></STRONG></SPAN><FONT face=Verdana><SPAN
style='FONT-SIZE: 8.5pt'>I hope 2005 was as good to you, your families
and your work life as it was for us here at Education Management
Solutions.<BR><BR>During 2005, EMS improved its product line, expanded
its audience, entered several new markets, and added the personnel
needed to continue our robust growth through 2006.<BR><BR>While
delighted with our progress and rosy future, we always remember that we
cannot go forward <BR>without you, our customers. Everything that EMS
produces, introduces, creates and implements all centers around what
will best serve the needs of our clients and our market.
<BR></SPAN></FONT><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: 'Times New
Roman'><BR></SPAN><FONT face=Verdana><SPAN style='FONT-SIZE:
8.5pt'>Throughout 2006, we will continue to strive for customer delight,
not just customer satisfaction. We'll be both proactive (creating
solutions to better serve you in the future) and reactive (handling your
questions and requests).&nbsp; We'll work hard to make sure you're happy
with your EMS solution.<BR></SPAN></FONT>";
ArrayList list = HTMLWorker.ParseToList(new StringReader(ss), null);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
t.AddCell(cell);
document.Add(t);
document.Close();

Paulo
-----Original Message-----
On Behalf Of sunilshishodia
Sent: Monday, November 06, 2006 9:45 AM
Subject: Re: [itextsharp-questions] Assigning HTML string to a PDFCell
Hi,
I am able to assign parsed html string to pdf cell but
what I am getting
is mingled string on pdf.I am attaching resultant pdf of the
code that I am
using to generate pdf.Code is as follows.
Dim document As Document = New Document(PageSize.A4,
80, 50, 30, 65)
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1
Dim cell As Cell
cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
table.AddCell(cell)
cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim strHtml As String = "<SPAN style='FONT-SIZE: 16pt;
FONT-FAMILY: 'Times New Roman'><STRONG><U><FONT
color=#000080>Happy 2006 to
our EMS Family and Friends!</FONT></U><BR><BR></STRONG></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>I hope 2005 was
as good to you,
your families and your work life as it was for us here at Education
Management Solutions.<BR><BR>During 2005, EMS improved its
product line,
expanded its audience, entered several new markets, and added
the personnel
needed to continue our robust growth through
2006.<BR><BR>While delighted
with our progress and rosy future, we always remember that we
cannot go
forward <BR>without you, our customers. Everything that EMS produces,
introduces, creates and implements all centers around what
will best serve
the needs of our clients and our market. <BR></SPAN></FONT><SPAN
style='FONT-SIZE: 11pt; FONT-FAMILY: 'Times New
Roman'><BR></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>Throughout 2006, we will
continue to strive for customer delight, not just customer
satisfaction.
We'll be both proactive (creating solutions to better serve you in the
future) and reactive (handling your questions and
requests).&nbsp; We'll
work hard to make sure you're happy with your EMS
solution.<BR></SPAN></FONT>"
Dim bytes As Byte() =
System.Text.Encoding.ASCII.GetBytes(strHtml)
Dim style As StyleSheet = New StyleSheet
Try
Dim srReader As New StreamReader(New
MemoryStream(bytes),
System.Text.Encoding.Default)
Dim alist As ArrayList
alist = HTMLWorker.ParseToList(srReader, style)
Dim alElement As IElement
For Each alElement In alist
cell.AddElement(alElement)
Next
Catch ex As Exception
End Try
table.AddCell(cell)
document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()
Also, does the height of the pdfcell that I am assigning HTML
, adjusts
automatically to the content i.e. increases if content increases.What
mistake I am making in code that is displaying mingled string in pdf
Regards
Post by Paulo Soares
I really can't get your problem. Your code can take a
String, assign it to
Post by Paulo Soares
StringReader, use or not use a style and create a PdfPCell.
So, you have
Post by Paulo Soares
an
HTML String and get a PdfPCell with the parsed HTML inside.
HTMLWorker
Post by Paulo Soares
won't
parse CSS if that's what you're asking.
Paulo
----- Original Message -----
Sent: Monday, November 06, 2006 5:24 AM
Subject: Re: [itextsharp-questions] Assigning HTML string
to a PDFCell
Post by Paulo Soares
Post by sunilshishodia
Hi,
I am sorry but i believe you could not get my problem. The code
ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
will add parsed html string to pdfcell. But, I have a HTML
string coming
Post by Paulo Soares
Post by sunilshishodia
from database and want to assign it to pdfcell. I wanted
to know whether
Post by Paulo Soares
Post by sunilshishodia
HTML can be directly assigned to pdfcell without using
String reader and
Post by Paulo Soares
Post by sunilshishodia
style. I want to preserve the style embedded in HTML
string , so , do not
Post by Paulo Soares
Post by sunilshishodia
want to make new style sheet to be passed to
HTMLWorker.ParseToList. Is
Post by Paulo Soares
Post by sunilshishodia
there any way out for this?
Regards
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf256
6338.html#a7193513
Post by Paulo Soares
Post by sunilshishodia
Sent from the itextsharp-questions mailing list archive at
Nabble.com.
--------------------------------------------------------------
-----------
Post by Paulo Soares
Post by sunilshishodia
Using Tomcat but need to do more? Need to support web
services, security?
Post by Paulo Soares
Post by sunilshishodia
Get stuff done quickly with pre-integrated technology to
make your job
Post by Paulo Soares
Post by sunilshishodia
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
Post by Paulo Soares
Post by sunilshishodia
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
--------------------------------------------------------------
-----------
Post by Paulo Soares
Using Tomcat but need to do more? Need to support web
services, security?
Post by Paulo Soares
Get stuff done quickly with pre-integrated technology to
make your job
Post by Paulo Soares
easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
Post by Paulo Soares
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf256
6338.html#a7195850
Sent from the itextsharp-questions mailing list archive at Nabble.com.
--------------------------------------------------------------
-----------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to make
your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.
sunilshishodia
2006-11-06 13:07:01 UTC
Permalink
Hi,

Thanks for your instant replies. I tried your way and was able to get the
desired result. I want a ceratin format in which pdf should be generated.I
am attaching that sample format. What i feel is required and need to be done
is that
1. I need to add pdftable to a pdfcell just like in HTML where table can be
added to td. Can we do this here? I am able to do first two part where Image
and below content is added but not sure how to make next part where content
is shown as a table inside cell is required and not sure if it can be done.

Regards
Post by Paulo Soares
Your PDF didn't show up. The following code in C# produces the attached
PDF.
FontFactory.RegisterDirectories();
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new
document.Open();
PdfPTable t = new PdfPTable(1);
String ss = "<SPAN style='FONT-SIZE: 16pt;FONT-FAMILY: Times New
Roman'><STRONG><U><FONT color=#000080>Happy 2006 to our EMS Family and
Friends!</FONT></U><BR><BR></STRONG></SPAN><FONT face=Verdana><SPAN
style='FONT-SIZE: 8.5pt'>I hope 2005 was as good to you, your families
and your work life as it was for us here at Education Management
Solutions.<BR><BR>During 2005, EMS improved its product line, expanded
its audience, entered several new markets, and added the personnel
needed to continue our robust growth through 2006.<BR><BR>While
delighted with our progress and rosy future, we always remember that we
cannot go forward <BR>without you, our customers. Everything that EMS
produces, introduces, creates and implements all centers around what
will best serve the needs of our clients and our market.
<BR></SPAN></FONT><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: 'Times New
8.5pt'>Throughout 2006, we will continue to strive for customer delight,
not just customer satisfaction. We'll be both proactive (creating
solutions to better serve you in the future) and reactive (handling your
questions and requests).&nbsp; We'll work hard to make sure you're happy
with your EMS solution.<BR></SPAN></FONT>";
ArrayList list = HTMLWorker.ParseToList(new StringReader(ss), null);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
t.AddCell(cell);
document.Add(t);
document.Close();
Paulo
-----Original Message-----
On Behalf Of sunilshishodia
Sent: Monday, November 06, 2006 9:45 AM
Subject: Re: [itextsharp-questions] Assigning HTML string to a PDFCell
Hi,
I am able to assign parsed html string to pdf cell but
what I am getting
is mingled string on pdf.I am attaching resultant pdf of the
code that I am
using to generate pdf.Code is as follows.
Dim document As Document = New Document(PageSize.A4,
80, 50, 30, 65)
Try
PdfWriter.GetInstance(document, New
FileStream("C:\Chap0507.pdf", FileMode.Create))
document.Open()
Dim table As Table = New Table(3)
table.BorderWidth = 1
table.BorderColor = New Color(0, 0, 255)
table.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER
Or Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
table.Padding = 1
table.Spacing = 1
Dim cell As Cell
cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
table.AddCell(cell)
cell = New Cell
cell.Header = False
cell.BorderWidth = 0
cell.Border = Rectangle.TOP_BORDER Or
Rectangle.BOTTOM_BORDER Or
Rectangle.LEFT_BORDER Or Rectangle.RIGHT_BORDER
cell.Colspan = 3
Dim strHtml As String = "<SPAN style='FONT-SIZE: 16pt;
FONT-FAMILY: 'Times New Roman'><STRONG><U><FONT
color=#000080>Happy 2006 to
our EMS Family and Friends!</FONT></U><BR><BR></STRONG></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>I hope 2005 was
as good to you,
your families and your work life as it was for us here at Education
Management Solutions.<BR><BR>During 2005, EMS improved its
product line,
expanded its audience, entered several new markets, and added
the personnel
needed to continue our robust growth through
2006.<BR><BR>While delighted
with our progress and rosy future, we always remember that we
cannot go
forward <BR>without you, our customers. Everything that EMS produces,
introduces, creates and implements all centers around what
will best serve
the needs of our clients and our market. <BR></SPAN></FONT><SPAN
style='FONT-SIZE: 11pt; FONT-FAMILY: 'Times New
Roman'><BR></SPAN><FONT
face=Verdana><SPAN style='FONT-SIZE: 8.5pt'>Throughout 2006, we will
continue to strive for customer delight, not just customer
satisfaction.
We'll be both proactive (creating solutions to better serve you in the
future) and reactive (handling your questions and
requests).&nbsp; We'll
work hard to make sure you're happy with your EMS
solution.<BR></SPAN></FONT>"
Dim bytes As Byte() =
System.Text.Encoding.ASCII.GetBytes(strHtml)
Dim style As StyleSheet = New StyleSheet
Try
Dim srReader As New StreamReader(New
MemoryStream(bytes),
System.Text.Encoding.Default)
Dim alist As ArrayList
alist = HTMLWorker.ParseToList(srReader, style)
Dim alElement As IElement
For Each alElement In alist
cell.AddElement(alElement)
Next
Catch ex As Exception
End Try
table.AddCell(cell)
document.Add(table)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
End Try
document.Close()
Also, does the height of the pdfcell that I am assigning HTML
, adjusts
automatically to the content i.e. increases if content increases.What
mistake I am making in code that is displaying mingled string in pdf
Regards
Post by Paulo Soares
I really can't get your problem. Your code can take a
String, assign it to
Post by Paulo Soares
StringReader, use or not use a style and create a PdfPCell.
So, you have
Post by Paulo Soares
an
HTML String and get a PdfPCell with the parsed HTML inside.
HTMLWorker
Post by Paulo Soares
won't
parse CSS if that's what you're asking.
Paulo
----- Original Message -----
Sent: Monday, November 06, 2006 5:24 AM
Subject: Re: [itextsharp-questions] Assigning HTML string
to a PDFCell
Post by Paulo Soares
Post by sunilshishodia
Hi,
I am sorry but i believe you could not get my problem. The code
ArrayList list = HTMLWorker.ParseToList(sReader, style);
PdfPCell cell = new PdfPCell();
foreach (IElement e in list)
cell.AddElement(e);
will add parsed html string to pdfcell. But, I have a HTML
string coming
Post by Paulo Soares
Post by sunilshishodia
from database and want to assign it to pdfcell. I wanted
to know whether
Post by Paulo Soares
Post by sunilshishodia
HTML can be directly assigned to pdfcell without using
String reader and
Post by Paulo Soares
Post by sunilshishodia
style. I want to preserve the style embedded in HTML
string , so , do not
Post by Paulo Soares
Post by sunilshishodia
want to make new style sheet to be passed to
HTMLWorker.ParseToList. Is
Post by Paulo Soares
Post by sunilshishodia
there any way out for this?
Regards
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf256
6338.html#a7193513
Post by Paulo Soares
Post by sunilshishodia
Sent from the itextsharp-questions mailing list archive at
Nabble.com.
--------------------------------------------------------------
-----------
Post by Paulo Soares
Post by sunilshishodia
Using Tomcat but need to do more? Need to support web
services, security?
Post by Paulo Soares
Post by sunilshishodia
Get stuff done quickly with pre-integrated technology to
make your job
Post by Paulo Soares
Post by sunilshishodia
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
Post by Paulo Soares
Post by sunilshishodia
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
--------------------------------------------------------------
-----------
Post by Paulo Soares
Using Tomcat but need to do more? Need to support web
services, security?
Post by Paulo Soares
Get stuff done quickly with pre-integrated technology to
make your job
Post by Paulo Soares
easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
Post by Paulo Soares
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
http://www.nabble.com/file/3982/Chap0507.pdf Chap0507.pdf
--
http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf256
6338.html#a7195850
Sent from the itextsharp-questions mailing list archive at Nabble.com.
--------------------------------------------------------------
-----------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to make
your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter
informação confidencial ou legalmente protegida. A incorrecta transmissão
desta mensagem não significa a perca de confidencialidade. Se esta
mensagem for recebida por engano, por favor envie-a de volta para o
remetente e apague-a do seu sistema de imediato. É proibido a qualquer
pessoa que não o destinatário de usar, revelar ou distribuir qualquer
parte desta mensagem.
This message is destined exclusively to the intended receiver. It may
contain confidential or legally protected information. The incorrect
transmission of this message does not mean the loss of its
confidentiality. If this message is received by mistake, please send it
back to the sender and delete it from your system immediately. It is
forbidden to any person who is not the intended receiver to use,
distribute or copy any part of this message.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
itextsharp-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Loading Image...
--
View this message in context: http://www.nabble.com/Assigning-HTML-string-to-a-PDFCell-tf2566338.html#a7198227
Sent from the itextsharp-questions mailing list archive at Nabble.com.
Loading...