Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

iTextSharp Create New Page When Parsing HTML

Posted on 2011-09-08
1
Medium Priority
?
1,237 Views
Last Modified: 2012-05-12
I am using iTextSharp (ver 5.1.2.0)  to create a PDF.  To generate my PDF file, I am parsing HTML to iTextSharp which is working fine.

But I want to be able to create a new page after certain sections of content in my HTML. I have seen some examples on the web that use "<newpage />" tag in the generated HTML for content to go onto another page. But it doesn't seem to be working.

Here is my code:

public static MemoryStream CreatePDF()
    {
        MemoryStream pdfMemStream = new MemoryStream();
        
        Document pdfDoc = new Document(PageSize.A4);
        PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, pdfMemStream);

        StringBuilder pdfBuilder = new StringBuilder();

        pdfBuilder.Append("<html>");
        pdfBuilder.Append("<body>");

        #region Executive Summary

        pdfBuilder.Append("<h1 style=\"color:#00a7c6;font-size:16px;\">Summary</h1><br />");
        pdfBuilder.Append("some text");
        pdfBuilder.Append("<br />");
        pdfBuilder.Append("<newpage />");
        pdfBuilder.Append("Text on new page.");

        #endregion

        pdfBuilder.Append("</body>");
        pdfBuilder.Append("</html>");

        StringReader reader = new StringReader(pdfBuilder.ToString());

        HTMLWorker parser = new HTMLWorker(pdfDoc);

        pdfDoc.Open();

        Font standardFont = FontFactory.GetFont("Verdana", 11);
        Font headerFont = FontFactory.GetFont("Arial", 24, new BaseColor(0, 167, 168));

        parser.Parse(reader);

        pdfDoc.Close();

        pdfMemStream.Close();

        return pdfMemStream;
    }

Open in new window

0
Comment
Question by:R1ND3R
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 36506915
I could be wrong, but I was under the impression that functionality was available with the HtmlToPdfBuilder class.

iTextSharp Utility
http://hugoware.net/blog/itextsharp-utility

This code allows for very simple HTML to be used to generate PDFs. It will not create complex pages automatically.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question