sunilshishodia
2006-11-03 07:04:32 UTC
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
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.
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.