Masoud Bahrami
Masoud Bahrami

Reputation: 111

Convert Persian HTML to PDF

When converting a html file with Persian content, the result does not contain appropriate Persian content. All Persian content shows as ???

Upvotes: 2

Views: 820

Answers (2)

Farzad Karimi
Farzad Karimi

Reputation: 780

now you can solve your problem by using itext7.pdfhtml and itext7.pdfcalligraph. install them using NuGet manager, and use this method to convert your Persian or Arabic Html to pdf :

public static void ConvertHtmlToPDF(string Html)
{
        ConverterProperties properties = new ConverterProperties();
        FontProvider fontProvider = new DefaultFontProvider();
        properties.SetFontProvider(fontProvider);

        PdfWriter writer = new PdfWriter(new FileStream(PDFFileAddressTobeGenerated, FileMode.Create));
        PdfDocument pdfDocument = new PdfDocument(writer);

        HtmlConverter.ConvertToPdf(htmlFile, pdfDocument, properties);
}

Upvotes: 1

Nic
Nic

Reputation: 12856

Are you starting your HTML with:

<!DOCTYPE html>    
<html>
    <head>
        <meta charset="utf-8">

Also ensure that the Persian fonts are installed locally.

Upvotes: 2

Related Questions