0

In my console application (.NET Core 2.2) I have a HTML string created with:

StringBuilder sb = new StringBuilder();
            sb.Append(@"<head>");
            sb.Append(@"<link href='"+ AAAA + "' rel='stylesheet'/>");
            sb.Append(@"</head>");
            sb.Append(@"<body>");
            sb.Append(@"<h1>test</h1>");
            sb.Append(@"</body>");
            return sb.ToString();

Where AAAA = Path.Combine(@"file:///C:/Users/asus/Desktop/IT/!!Trials!!/02_APIs/HtmlToPdf_06_CV_Spike/HtmlToPdf/bin/Debug/netcoreapp2.2/styles.css"); is file path, regarding https://github.com/rdvojmoc/DinkToPdf/issues/27#issuecomment-417792667

And it does not work for me. Style sheet does not changes styles on HTML. I also tried sb.Append(@"<link href='styles.css' rel='stylesheet'/>"); with the same result.

Please note, that styles.css file is located in project main folder, also in (...)Debug/netcoreapp2.2.

Actually I ran out of ideas and inspirations, from here and SO, how to make my HTML to use CSS in my console application. Is it possible at all? Thank you in advance for your help.

Project tree:

enter image description here

bakunet
  • 559
  • 8
  • 25

2 Answers2

1

This cannot be a good solution. The file path will be different on the server. Will not work for non-windows server

user762912
  • 103
  • 2
  • 2
  • 6
0

Allright, I found solution: https://stackoverflow.com/a/20357784/12603542 Need also add: file:/// before.

private static string CreateHtmlHead()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"<head>");
            sb.Append(@"<link href='file:///C:\Users\asus\Desktop\IT\!!Trials!!\02_APIs\HtmlToPdf_06_CV_Spike\HtmlToPdf\bin\Debug\netcoreapp2.2\styles.css' rel='stylesheet' type='text/css' media='screen'/>");
            sb.Append(@"</head>");

            return sb.ToString();
        }
bakunet
  • 559
  • 8
  • 25