ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Export arabic or parsi languages to PDF using itextSharp in ASP.Net<p>I am working on it i will get back to you soon.</p>https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/Tue, 17 Apr 2018 04:52:49 GMTExport arabic or parsi languages to PDF using itextSharp in ASP.Net<p>Hi <a class="username" rel="Mohammadmk">Mohammadmk</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;div class=&#34;lead&#34; id=&#34;MyDiv&#34; runat=&#34;server&#34;&gt; &lt;p&gt; 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 4.0.0.2323 Type &#39;get-help NuGet&#39; to see all available NuGet commands. &lt;/p&gt; &lt;div class=&#34;lead&#34; style=&#34;direction: rtl;&#34;&gt; &lt;p&gt; لاوروف: آخرین ذره اعتمادمان به غرب را هم داریم از دست می&zwnj;دهیم&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;asp:Button ID=&#34;btnConvert&#34; Text=&#34;Convert&#34; runat=&#34;server&#34; OnClick=&#34;btnConvert_Click&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; using System.Text;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.html.simpleparser Imports iTextSharp.text.pdf Imports System.Text</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void btnConvert_Click(object sender, EventArgs e) { string strHtml = string.Empty; string pdfFileName = Server.MapPath(&#34;~/files/div.pdf&#34;); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); MyDiv.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); strHtml = sr.ReadToEnd(); sr.Close(); CreatePDFFromHTMLFile(&#34;&lt;div style=&#39;font-family:arial unicode ms;&#39;&gt;&#34; + strHtml + &#34;&lt;/div&gt;&#34;, pdfFileName); Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;Content-Disposition&#34;, string.Format(&#34;attachment; filename=\&#34;{0}\&#34;&#34;, &#34;div.pdf&#34;)); Response.ContentEncoding = Encoding.UTF8; Response.WriteFile(pdfFileName); Response.HeaderEncoding = Encoding.UTF8; Response.Flush(); Response.End(); } private void CreatePDFFromHTMLFile(string html, string FileName) { TextReader reader = new StringReader(html); Document document = new Document(PageSize.A4, 30, 30, 30, 30); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(FileName, FileMode.Create)); HTMLWorker worker = new HTMLWorker(document); document.Open(); FontFactory.Register(&#34;C:\\Windows\\Fonts\\ARIALUNI.TTF&#34;, &#34;arial unicode ms&#34;); iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet(); ST.LoadTagStyle(&#34;body&#34;, &#34;encoding&#34;, &#34;Identity-H&#34;); worker.SetStyleSheet(ST); worker.StartDocument(); worker.Parse(reader); worker.EndDocument(); worker.Close(); document.Close(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub btnConvert_Click(ByVal sender As Object, ByVal e As EventArgs) Dim strHtml As String = String.Empty Dim pdfFileName As String = Server.MapPath(&#34;~/files/div.pdf&#34;) Dim sw As StringWriter = New StringWriter() Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) MyDiv.RenderControl(hw) Dim sr As StringReader = New StringReader(sw.ToString()) strHtml = sr.ReadToEnd() sr.Close() CreatePDFFromHTMLFile(&#34;&lt;div style=&#39;font-family:arial unicode ms;&#39;&gt;&#34; &amp; strHtml &amp; &#34;&lt;/div&gt;&#34;, pdfFileName) Response.ContentType = &#34;application/pdf&#34; Response.AddHeader(&#34;Content-Disposition&#34;, String.Format(&#34;attachment; filename=&#34;&#34;{0}&#34;&#34;&#34;, &#34;div.pdf&#34;)) Response.ContentEncoding = Encoding.UTF8 Response.WriteFile(pdfFileName) Response.HeaderEncoding = Encoding.UTF8 Response.Flush() Response.[End]() End Sub Private Sub CreatePDFFromHTMLFile(ByVal html As String, ByVal FileName As String) Dim reader As TextReader = New StringReader(html) Dim document As Document = New Document(PageSize.A4, 30, 30, 30, 30) Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream(FileName, FileMode.Create)) Dim worker As HTMLWorker = New HTMLWorker(document) document.Open() FontFactory.Register(&#34;C:\Windows\Fonts\ARIALUNI.TTF&#34;, &#34;arial unicode ms&#34;) Dim ST As iTextSharp.text.html.simpleparser.StyleSheet = New iTextSharp.text.html.simpleparser.StyleSheet() ST.LoadTagStyle(&#34;body&#34;, &#34;encoding&#34;, &#34;Identity-H&#34;) worker.SetStyleSheet(ST) worker.StartDocument() worker.Parse(reader) worker.EndDocument() worker.Close() document.Close() End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/yr0LgEC.jpg" alt="" width="472" height="191" /></p> <p>Refering below link i have created the example.</p> <p><a href="https://stackoverflow.com/questions/10329863/display-unicode-characters-in-converting-html-to-pdf">https://stackoverflow.com/questions/10329863/display-unicode-characters-in-converting-html-to-pdf</a></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/Tue, 17 Apr 2018 06:11:19 GMTExport arabic or parsi languages to PDF using itextSharp in ASP.Net<p><strong>thanks for the help&nbsp;</strong></p> <p>but here is a small issue while we are converting div into pdf format file</p> <p>the sentence which is in persian or arabic both are not the same&nbsp;</p> <p>&nbsp;</p> <p>in the pdf&nbsp; each word are sepetated into single single alphabits&nbsp; for example&nbsp;&nbsp;</p> <p>this is the actual word&nbsp;<span style="color: #008000;"><strong> "اعتمادمان"</strong>&nbsp;<span style="color: #000000;"> and after converting to pdf the word is like this&nbsp;<span style="color: #993300;"><strong>"اع ت م ادم ان"&nbsp;&nbsp;<span style="color: #000000;">in arabic or persian languages most of the alphabits are clinged to each other&nbsp;&nbsp;</span></strong></span></span></span></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/Wed, 18 Apr 2018 00:27:03 GMTExport arabic or parsi languages to PDF using itextSharp in ASP.Net<p>Hi <a class="username" rel="Mohammadmk">Mohammadmk</a>,</p> <p>Important for Arabic, Persian or Urdu Text you need to assign RUN_DIRECTION_RTL.</p> <p>For more details refer below article.</p> <h1 class="header"><a title="iTextSharp: Generate PDF in Arabic, Persian (Farsi) and Urdu Language Characters in ASP.Net'a" href="https://www.aspsnippets.com/Articles/iTextSharp-Generate-PDF-in-Arabic-Persian-Farsi-and-Urdu-Language-Characters-in-ASPNet.aspx">iTextSharp: Generate PDF in Arabic, Persian (Farsi) and Urdu Language Characters in ASP.Net</a></h1>https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/https://www.aspforums.net:443/Threads/105069/Export-arabic-or-parsi-languages-to-PDF-using-itextSharp-in-ASPNet/Wed, 18 Apr 2018 06:30:34 GMT