Click here to Skip to main content
15,041,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert html file into pdf file . please give me sample code in c#
Posted

1 solution

This question is ambiguous, you are not specifying the version of ItextSharp you are using not even the situation you are in. If you googled the keywords of you question you will get the answer in less then a second. However,

private MemoryStream createPDF(string html)
    {
        MemoryStream msOutput = new MemoryStream();
        TextReader reader = new StringReader(html);

        // step 1: creation of a document-object
        Document document = new Document(PageSize.A4, 30, 30, 30, 30);            

        // step 2:
        // we create a writer that listens to the document
        // and directs a XML-stream to a file
        PdfWriter writer = PdfWriter.GetInstance(document, msOutput);

        // step 3: we create a worker parse the document
        HTMLWorker worker = new HTMLWorker(document);

        // step 4: we open document and start the worker on the document
        document.Open();
        worker.StartDocument();

        // step 5: parse the html into the document
        worker.Parse(reader);

        // step 6: close the document and the worker
        worker.EndDocument();
        worker.Close();
        document.Close();

        return msOutput;
    }


Source: http://stackoverflow.com/questions/2822843/itextsharp-html-to-pdf[^]

Cheers
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900