1

I am trying to print a pdf with external css file but my file reads from xml perfectly but does not apply the css to the pdf.

I have tried to do this code :

pdfDoc.Open();

string css = "D:\\Office\\cases_converter_tool\\cases_converter_tool\\styleCase.css ";
var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCss(css, "utf-8", true);

//var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);

XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, pdfDoc, new StreamReader("C:\\Users\\Dip\\Desktop\\MLRA_1982_402.xml")

PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport);
pdfWriter.PageEvent = new ITextEvents();

pdfDoc.Open();
string css = "D:\\Office\\cases_converter_tool\\cases_converter_tool\\styleCase.css ";
var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCss(css, "utf-8", true);

XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, pdfDoc, new StreamReader("C:\\Users\\Dip\\Desktop\\MLRA_1982_402.xml"));

I expect the xml data should not overlaps with my headings.It shall leave a certain gap in the beginning and the end of the page for headers and footers section.

kara
  • 3,205
  • 4
  • 20
  • 34
Face Rast
  • 19
  • 5
  • In the last line: why don't you use cssResolver.ParseXhtml? You already have the instance in the cssResolver. – Leon Apr 11 '19 at 08:36
  • I tried to do : cssResolver.ParseXhtml but it show no method for cssResolver. – Face Rast Apr 11 '19 at 09:35
  • I am Sorry that was my mistake, the GetDefaultCssResolver returns an CssResolver and not the instance. – Leon Apr 11 '19 at 09:45
  • So,what should be the correct way to approach the problem ? i want to leave some space at the start and end for my headers and footers. – Face Rast Apr 11 '19 at 09:52
  • Please take a look at this post: [CSS styles not being applied to PDF with iTextSharp](https://stackoverflow.com/questions/18131992/css-styles-not-being-applied-to-pdf-with-itextsharp) Maybe this helps out. – Leon Apr 11 '19 at 11:11

0 Answers0