Solved

iTextSharp Create New Page When Parsing HTML

Posted on 2011-09-08
1
1,169 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
crm development 2 68
Name space syntax error 12 44
ASP.net Have sliders change in order 2 10
Executing SSIS with a Stored Procedure Permissions 12 29
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now