Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

itextsharp "the document has no pages" error when i have anchor tag

I am converting some html to pdf. It is working fine but when i have anchor tag in my html i get error the document has no pages

My code is

 byte[] data;
 using (var sr = new StringReader(sw.ToString()))
 {
    var st = new StyleSheet();

    GetStyleSheetForUnicodeCharacters(st);
    using (var ms = new MemoryStream())
    {
       using (var pdfDoc = new Document())
       {                            
           using (var w = PdfWriter.GetInstance(pdfDoc, ms))
           {
              pdfDoc.Open();
              var parsedHtmlElements = HTMLWorker.ParseToList(sr, st);
              foreach (var htmlElement in parsedHtmlElements)
              {
                 pdfDoc.Add(htmlElement as IElement);
              }
              pdfDoc.Close();
              data = ms.ToArray();
           }
       }
    }
 }
like image 700
Kamran Shahid Avatar asked Nov 10 '22 05:11

Kamran Shahid


1 Answers

The problem may be invalid html. One way to check is to run your html source through a validator such W3C Markup Validation Service.

like image 96
drobison Avatar answered Nov 14 '22 21:11

drobison