iTextSharp создает PDF с пустыми страницами

Я только что добавил в свой проект пакет нюгетеров iTextSharp XMLWorker (и его зависимости) и пытаюсь преобразовать HTML-код из строки в файл PDF, хотя исключения не создаются, файл PDF создается с две пустые страницы. Зачем?

Предыдущая версия кода использовала только iTextSharp 5.5.8.0 с HTMLWorker и методом ParseList, затем я переключился на

Вот код, который я использую:

public void ExportToPdf() {
 string htmlString = "";

 Document document = new Document(PageSize.A4, 40, 40, 40, 40);
 var memoryStream = new MemoryStream();

 PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
 document.Open();

 htmlString = sbBodyMail.ToString();

 XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, new StringReader(htmlString));

 document.Close();
 DownloadFile(memoryStream);
}

public void DownloadFile(MemoryStream memoryStream) {
 //Clears all content output from Buffer Stream
 Response.ClearContent();
 //Clears all headers from Buffer Stream
 Response.ClearHeaders();
 //Adds an HTTP header to the output stream
 Response.AddHeader("Content-Disposition", "attachment;filename=Report_Diagnosis.pdf");
 //Gets or Sets the HTTP MIME type of the output stream
 Response.ContentType = "application/pdf";
 //Writes the content of the specified file directory to an HTTP response output stream as a file block
 Response.BinaryWrite(memoryStream.ToArray());
 //Response.Write(doc);
 //sends all currently buffered output to the client
 Response.Flush();
 //Clears all content output from Buffer Stream
 Response.Clear();
}

Если я ставлюdocument.Add(new Paragraph("Just a test")); прямо передdocument.Close(); абзац отображается на второй странице, но остальная часть документа остается пустой.

ОБНОВИТЬ

Я изменил HTML вhtmlString переменная простоDIV иTABLE и это сработало. Итак, теперь возникает вопрос: как мне узнать, какая часть HTML вызывает какую-то ошибку в XMLWorker?

Ответы на вопрос(1)

Ваш ответ на вопрос