Export arabic or parsi languages to PDF using itextSharp in ASP.Net

Last Reply one year ago By dharmendr

Posted one year ago

here is the code that i used 


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DivToPdf.aspx.cs" Inherits="divtopdf.DivToPdf" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <div class="lead" id="MyDiv" runat="server">
                Each package is licensed to you by its owner. NuGet is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.
Package Manager Console Host Version
Type 'get-help NuGet' to see all available NuGet commands.
        <div class="lead" style="direction:rtl;">
            <p> لاوروف: آخرین ذره اعتمادمان به غرب را هم داریم از دست می‌دهیم</p>

        <asp:Button ID="btnConvert" Text="Convert" runat="server" OnClick="btnConvert_Click" />


and this is the button event based onclick event


protected void btnConvert_Click(object sender, EventArgs e)
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=div.pdf");

            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

            StringReader stringReader = new StringReader(stringWriter.ToString());
            Document Doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(Doc);
            PdfWriter.GetInstance(Doc, Response.OutputStream);



You are viewing reply posted by: dharmendr one year ago.
Posted one year ago

Hi Mohammadmk,

Important for Arabic, Persian or Urdu Text you need to assign RUN_DIRECTION_RTL.

For more details refer below article.

iTextSharp: Generate PDF in Arabic, Persian (Farsi) and Urdu Language Characters in ASP.Net