How to check if a document has no pages

I am trying to use iTextSharp to convert some HTML mail from Outlook to PDF. Some post gives a problem for HTMLWorker

throwing exceptions.

If this happens, I want to catch the exception and refuse to create the PDF. But I can not. What do I need to do to check and close open correctly Document

?

+3


source to share


2 answers


Just before calling, Close()

you can check the property of PageNumber

yours Document

to see if there are any pages.

if (doc.PageNumber == 0) {
    //Do something here
}
doc.Close();

      



In addition, the class is HTMLWorker

not actively developed . Instead, almost all of the new HTML parsing code runs in a separate library called XMLWorker

. Below is @kuujinbo's sample code.

+3


source


Start on a new page and add your paragraphs:



Document document = new Document();

document.Open();

foreach (var item in List)
{
   document.NewPage();
   AddParagraph(item, document);
}

document.Close();

      

0


source







All Articles