Hi .
We are attempting to include the Itextsharp library on a asp.net project with
Visual Basic. We made many tests generating a pdf file from a HTML, wich
contains a css style, and in all tests the library didn“t work well. In our
tests the styles were ignored, causing a lost of the style on the file
generated.
You can see below the functions we are using to generate the Pdf file. We have
tried the 3 functions without sucess.
<Code>
Private Function MakePDF(ByVal controlRender As Control) As Document
Dim strHeader As String = Nothing
Dim stw As StringWriter = New StringWriter()
Dim htextw As HtmlTextWriter = New HtmlTextWriter(stw)
Dim image As Image = Nothing
controlRender.RenderControl(htextw)
Dim document As text.Document = New text.Document(text.PageSize.A4, 70.0, 70.0,
100.0, 70.0)
Dim pdfEscritor As PdfWriter = PdfWriter.GetInstance(document,
Response.OutputStream)
Dim page As pdfPage = New pdfPage()
'create an instance of the PdfWriter and write to the Response.OutputStream.
This will stream it directly to the browser
document.Open()
Dim str As StringReader = New StringReader(stw.ToString())
Dim htmlworker As HTMLWorker = New HTMLWorker(document)
Dim styles As New iTextSharp.text.html.simpleparser.StyleSheet
styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTSIZE, "8") ' this works
Dim dicStylesPrincipal As New Dictionary(Of String, String)
Dim dicStylesDados As New Dictionary(Of String, String)
Dim dicStylesSpan As New Dictionary(Of String, String)
Dim dicStylesTabela As New Dictionary(Of String, String)
Dim objects As List(Of IElement) = Nothing
dicStylesPrincipal.Add("display", "table")
dicStylesPrincipal.Add("width", "200px")
dicStylesDados.Add("float", "left")
dicStylesDados.Add("padding", "40px")
dicStylesDados.Add("background-color", "red")
dicStylesSpan.Add("background-color", "red")
dicStylesTabela.Add("background-color", "blue")
'styles.LoadStyle("tabela", dicStylesTabela)
'styles.LoadStyle("#tabela", dicStylesTabela)
styles.LoadStyle(".tabela", dicStylesTabela) ' this not works
' styles.LoadStyle("divTabela", dicStylesPrincipal)
' styles.LoadStyle("#divTabela", dicStylesPrincipal)
styles.LoadStyle(".divTabela", dicStylesPrincipal)
' styles.LoadStyle("divDados", dicStylesDados)
styles.LoadStyle("divDados", "style", "float:left;padding:40px;
font-size:5px;border:1px solid;")
'styles.LoadStyle("#divDados", dicStylesDados)
'styles.LoadStyle(".divDados", dicStylesDados)
'styles.LoadStyle("spanteste", dicStylesSpan)
'styles.LoadStyle("#spanteste", dicStylesSpan)
'styles.LoadStyle(".spanteste", dicStylesSpan)
' styles.LoadTagStyle("div", "style",
"background-color:red;font-size:5px;color:#505f7e")
objects = htmlworker.ParseToList(str, styles)
For k As Integer = 0 To objects.Count - 1
If TypeOf (DirectCast(objects(k), IElement)) Is pdf.PdfPTable Then
DirectCast(objects(k), PdfPTable).SplitLate = False
End If
document.Add(DirectCast(objects(k), IElement))
Next
document.Close()
Return document
End Function
' Creates a PDF file and sends to the client
Protected Sub btnExportPDF_Click(sender As Object, e As EventArgs) Handles
btnExportPDF.Click
Response.ClearContent()
Response.AddHeader("content-disposition", "attachment; filename=Reports.pdf")
Response.ContentType = "application/pdf"
Dim stw As StringWriter = New StringWriter()
Dim htextw As HtmlTextWriter = New HtmlTextWriter(stw)
ConteudoExportar.RenderControl(htextw)
Response.Write(MakePDF(ConteudoExportar))
Response.End()
End Sub
</Code>
I would appreciate your help.
Thank you.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php