I'm trying to convert a simple HTML to PDF using iTextSharp. Consider the below scenario, where HTML div width will not fit within PDF Page size, content is blank in PDF.
TextReader reader = new StringReader(html);
using (MemoryStream memoryStream = new MemoryStream())
{
using (Document document = new Document(PageSize.A4, 0, 0, 36, 0))
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destPath, FileMode.Create));
writer.ViewerPreferences = PdfWriter.PageModeUseOutlines | PdfWriter.PageLayoutSinglePage;
writer.CloseStream = false;
document.Open();
//writer.PageEvent = new HeaderFooterHelper();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser parser = new XMLParser(true, worker, Encoding.Unicode);
parser.Parse(reader);
worker.Close();
document.Close();
}
}
HTML Input :
<html>
<head>
</head>
<body>
<div style="width:1000px">
Blood is needed for emergencies and for people who have cancer, blood disorders,sickle cell, anemia and other illnesses. Some people need regular blood transfusions to live. For nearly 5 million people who receive blood transfusions every year, your donation can make the difference between life and death
</div>
</body>
</html>
We are migrating PDFs generated from EVO to iTextSharp. This is one of the issue faced during migration process. So content cannot be changed/manipulated based on pdf page size. In specific, looking for a solution with PageSize.A4 option.