HTML-Renderer icon indicating copy to clipboard operation
HTML-Renderer copied to clipboard

External CSS

Open Kagelol opened this issue 8 years ago • 9 comments

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..

Kagelol avatar Feb 14 '17 15:02 Kagelol

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

nea avatar Feb 14 '17 15:02 nea

Ah yes perfect! exactly what i was looking for.

Kagelol avatar Feb 15 '17 11:02 Kagelol

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

rkarina avatar Mar 08 '17 23:03 rkarina

I wrote the CSS in a string, i didnt feed it a file

Kagelol avatar Mar 08 '17 23:03 Kagelol

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);

rkarina avatar Mar 08 '17 23:03 rkarina

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

Kagelol avatar Mar 08 '17 23:03 Kagelol

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.

rkarina avatar Mar 08 '17 23:03 rkarina

Hi, I have tried line-height using pt values. But it seems to ignored it.

erocmiles avatar Nov 10 '18 12:11 erocmiles

hi guys, any solution for this post?

Botello1 avatar Sep 26 '19 00:09 Botello1