简体   繁体   中英

Why am I getting error CS0246: The type or namespace name could not be found when trying to use OpenHtmlToPdf?

I'm trying to use OpenHtmlToPdf to convert a Html file to pdf. This is the code i'm trying to run:

using System.IO;
using OpenHtmlToPdf;

namespace Converter{
    class Html_to_Pdf
    {
        static void Main(string[] args){
            var html = Pdf.From(@"C:/Temp/input.html").OfSize(PaperSize.A4);
            byte[] content = html.Content();
            File.WriteAllBytes(@"C:/Temp/output.pdf", content);
        }
    }
}

And this is the error that i get when i try to compile the code:

[Running] dotnet "C:\Users\janik\AppData\Roaming\Code\User\cs-script.user\dotnet\cscs.dll" "d:\Github\ionesoft_ebook_to_pdf\Scripts\converter.cs"
Error: Specified file could not be compiled.

d:\Github\ionesoft_ebook_to_pdf\Scripts\converter.cs(2,7): error CS0246:  The type or namespace name "OpenHtmlToPdf" could not be found (are you missing a using directive or an assembly reference?)
d:\Github\ionesoft_ebook_to_pdf\Scripts\converter.cs(2,7): error CS0246:  The type or namespace name "OpenHtmlToPdf" could not be found (are you missing a using directive or an assembly reference?)


[Done] exited with code=0 in 2.183 seconds

So what am i doing wrong here because according to me i'm not mussung anything. I'm using visual studio code but i don't know if that has something to do with it.

You can use this command dotnet add package OpenHtmlToPdf to add a reference to you project. This will add a package reference in your.csproj file. Once done run this command dotnet restore to restore your packages.

For your reference: dotnet add package

Edit: You can Add Nuget Package Manager Extension. After it is Added, perform below steps:

  1. Press Ctrl+Shift+P
  2. Type OpenHtmlToPdf
  3. Choose Package and then the version number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM