External CSS
Im trying to write an application which converts HTML to PDF. I have tried to cram it all in one string HTML and CSS but it does not seem to like it. I noticed there is a way to add external CSS to the generatepdf command, however i have no idea how to create the CSSdata properly, does anyone know? i cannot seem to find any documentation on it either..
Hi there
The PdfGenerator.cs class has a static method ParseStyleSheet which returns the required CssData, generated from a string.
https://github.com/ArthurHub/HTML-Renderer/blob/cc3b5c221b192a950d3d53b561ac01049668e239/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs#L56
Is that what you were looking for?
Best
Ah yes perfect! exactly what i was looking for.
Can any of you guys/girls provide an example on how to use the above method?
This is what I'm currently doing:
string testStylesheet = "~/Scripts_RMS/Shared/FormLetter/ckeditor.css"; var cssData = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.ParseStyleSheet(testStylesheet, true); doc = PdfGenerator.GeneratePdf(m_Html, GetConfig(nPageSize), cssData);
Any thoughts?
Cheers,
Adhy
I wrote the CSS in a string, i didnt feed it a file
So you did something similar to this?
string testStylesheet = "<style type="text/css">p { line-height: 1!important; }</style>"; var cssData = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.ParseStyleSheet(testStylesheet, true);
without the style tag, plain CSS
i had something like
string css = ".img { position: something; }" +
".otherclass { color:white; }";
Something like that, i dont have my source handy right now
Thanks, I'll give this a go. Have you played around with line-height CSS by any chance? It seems that the PDF converter doesn't work for pt values, though I'm not 100% sure.
Hi, I have tried line-height using pt values. But it seems to ignored it.
hi guys, any solution for this post?