PlanetJava
Custom Search

java-lib-itext-general
[Top] [All Lists]

HTML to PDF with XMLWorker

Subject: HTML to PDF with XMLWorker
Date: Wed, 20 Jun 2012 15:08:06 -0400
Hello Everyone and thanks for your help in advance. I am trying to
convert a simple HTML file to PDF using iTextSharp xmlworker. Below is
the code.  However, when open the PDF file, I receive an error message
the file  could not be opened and it is damaged.  Here is my code.  Any
help would be greatly appreciated.  Thanks.
Imports System.IO
Imports System.Text
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.tool.xml.css
Imports iTextSharp.tool.xml
Imports iTextSharp.tool.xml.pipeline.html
Imports iTextSharp.tool.xml.html
Imports iTextSharp.tool.xml.pipeline.css
Imports iTextSharp.tool.xml.parser
Imports iTextSharp.tool.xml.pipeline.end
Public Class Form1
    Private Sub Form1_Load(sender As System.Object, e As
System.EventArgs) Handles MyBase.Load
        Dim memStream As New MemoryStream()
        Dim outXml As String = "C:\test.htm"
        Dim xmlString As New StringReader(outXml)
        Dim document As New
iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0)
        Dim ResultFile As String = "C:\result.pdf"
        Dim writer As PdfWriter = PdfWriter.GetInstance(document, New
System.IO.FileStream(ResultFile, System.IO.FileMode.Create))
        document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
        document.Open()
        Dim cssFiles As New CssFilesImpl()
        cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS())
        Dim cssRevolver As New StyleAttrCSSResolver()
        Dim htmlContext As New HtmlPipelineContext(cssRevolver)
        htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
        'htmlContext.SetImageProvider(New MyImageProvider(imagePath))
        Dim pipeline As IPipeline = New CssResolverPipeline(cssRevolver,
New HtmlPipeline(htmlContext, New PdfWriterPipeline(document, writer)))
        Dim worker As New XMLWorker(pipeline, True)
        Dim p As New XMLParser(worker)
        p.Parse(xmlString)
        document.Close()
    End Sub
End Class
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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
msgmiddle
<Prev in Thread] Current Thread [Next in Thread>
  • HTML to PDF with XMLWorker,
Current Sitemap | © 2012 planetjava | Contact | Privacy Policy