Tamás Deák
Tamás Deák

Reputation: 175

c# html file encoding iso-8859-2

I have this html file: http://mek.oszk.hu/17700/17789/17789.htm, which I already downloaded.

This html file has iso-8859-2 charset.

I want to convert this HTML file to a PDF file with IronPdf nuget package.

I tried this, but It doesn't work:

using (StreamReader stream = new StreamReader(book.Source,Encoding.GetEncoding("ISO-8859-2")))
{
    HtmlDocument htmlDocument = new HtmlDocument();
    htmlDocument.Load(stream);
    var Renderer = new IronPdf.HtmlToPdf();
    var PDF = Renderer.RenderHtmlAsPdf(htmlDocument.DocumentNode.OuterHtml);
    var OutputPath = "HtmlToPDF.pdf";
    PDF.SaveAs(OutputPath);
    System.Diagnostics.Process.Start(OutputPath);
}

My output result: enter image description here

UPDATE 1: I want to this output result:

enter image description here

Upvotes: 0

Views: 350

Answers (1)

owairc
owairc

Reputation: 1978

For me it's Magyar :) but obtained a better result with this piece of code:

            var Renderer = new IronPdf.HtmlToPdf();
            var PDF = Renderer.StaticRenderHTMLFileAsPdf("17789.htm", new IronPdf.PdfPrintOptions() { InputEncoding = Encoding.GetEncoding("ISO-8859-2") });
            var OutputPath = "HtmlToPDF.pdf";
            PDF.SaveAs(OutputPath);
            System.Diagnostics.Process.Start(OutputPath);

Upvotes: 1

Related Questions