Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

iTextSharp Create New Page When Parsing HTML

Posted on 2011-09-08
1
Medium Priority
?
1,262 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 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