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 commanddotnet 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: