Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
<pre> public byte[] GetPDF(string pHTML)
    {
        byte[] bPDF = null;

        MemoryStream ms = new MemoryStream();
        TextReader txtReader = new StringReader(pHTML);
       
        // we retrieve the total number of pages
        
        // 1: create object of a itextsharp document class
        Document doc = new Document(PageSize.LEGAL_LANDSCAPE, 10, 10, 42, 35);
        doc.SetPageSize(new Rectangle(850f, 1100f));
        // 2: we create a itextsharp pdfwriter that listens to the document and directs a XML-stream to a file
        PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);

        // 3: we create a worker parse the document
        HTMLWorker htmlWorker = new HTMLWorker(doc);
        
        // 4: we open document and start the worker on the document
        doc.Open();
        doc.NewPage();

        //htmlWorker.StartDocument();

        //// 5: parse the html into the document
        //htmlWorker.Parse(txtReader);
        List<IElement> elements = HTMLWorker.ParseToList(txtReader, null);
        foreach (IElement el in elements)
        {
            //If the element is a table manually set its header row count
            if (el is PdfPTable)
            {
                ((PdfPTable)el).HeaderRows = 2;

            }
            doc.Add(el);
        }
       

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

        bPDF = ms.ToArray();

        return bPDF;
    }


What I have tried:

i want add page number every page in export pdf 
Posted
Updated 18-May-18 6:33am

1 solution

 
Share this answer
 

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